Reply to Re: help - isolate specific xml from mySQL entry?

Your name:

Reply:


Posted by Jim Michaels on 02/27/06 22:06

"henshu" <henshu_san@hotmail.com> wrote in message
news:CgILf.108$8d1.4@read1.cgocable.net...
>I wonder if its possible to "extract"/copy/parse a specific line of xml
>from my mySQL table - isolate it from the rest of the mysql entry (on PHP
>display)?
>
> example (as mySQL see's it):
> "Today is sunny <img src="/pictures/sun.gif" /> with chances of rain <img
> src="/pictures/raincloud.jpg" width="50" alt="rain" title="rain" /> this
> evening. So you may want to carry your umbrella on your way to work."
>
> isolated out to:
> <img src="/pictures/sun.gif" /><img src="/pictures/raincloud.jpg"
> width="50" alt="rain" title="rain" />


<?php
//extract images from XHTML string
$contents="Today is sunny <img src=\"/pictures/sun.gif\" /> with chances of
rain
<img src=\"/pictures/raincloud.jpg\" width=\"50\" alt=\"rain\"
title=\"rain\" />
this evening. So you may want to carry your umbrella on your way to work.";
$doc = DOMDocument::loadHTML($contents);
//could be loadXML(), but it requires the header stuff. loadHTML() is more
forgiving
$doc->saveHTML(); //turns into a proper HTML document
$imgs=$doc->getElementsByTagName("img");
foreach ($imgs as $img) {
echo "<img src=\"".$img->getAttribute("src")."\"";
if ($img->getAttribute("width")) { echo "
width=\"".$img->getAttribute("width")."\"";}
if ($img->getAttribute("height")) { echo "
height=\"".$img->getAttribute("height")."\"";}
if ($img->getAttribute("alt")) { echo "
alt=\"".$img->getAttribute("alt")."\"";}
if ($img->getAttribute("title")) { echo "
title=\"".$img->getAttribute("title")."\"";}
if ($img->getAttribute("align")) { echo "
align=\"".$img->getAttribute("align")."\"";}
if ($img->getAttribute("hspace")) { echo "
hspace=\"".$img->getAttribute("hspace")."\"";}
if ($img->getAttribute("vspace")) { echo "
vspace=\"".$img->getAttribute("vspace")."\"";}
if ($img->getAttribute("ismap")) { echo "
ismap=\"".$img->getAttribute("ismap")."\"";}
if ($img->getAttribute("usemap")) { echo "
usemap=\"".$img->getAttribute("usemap")."\"";}
echo " />\n";
}

?>


there may be other attributes like id, name, border, align.


>
>
> In this example I'm trying to make a PHP file that isolates and displays
> only the img src tags, ignoring the text spiel attached to it. Of course I
> can get the whole entry from mySQL to pop-up in the PHP (all the regular
> text + the images), but I have yet to figure out a way just to have the
> images showing (since they share the same mySQL table, I can't isolate it
> normally as if it were 2 different columns/tables).

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация