Bluehost.com Web Hosting $6.95

help - isolate specific xml from mySQL entry?

This is a discussion on help - isolate specific xml from mySQL entry? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I wonder if its possible to "extract"/copy/parse a specific line of xml from my mySQL table - ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-24-2006
henshu
 
Posts: n/a
Default help - isolate specific xml from mySQL entry?

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" />


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).
Reply With Quote
  #2 (permalink)  
Old 02-24-2006
Tommy Gildseth
 
Posts: n/a
Default Re: help - isolate specific xml from mySQL entry?

henshu wrote:

> 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" />


I do not believe that will be possible using only SQL, and I'm not even sure
it's adviseable.
You will probably need to do some post processing with PHP. It can probably
be done using regex, or you can use XML DOM functions to parse the XML, and
extract all the child nodes using for ex. XPATH.

--
Tommy
http://design.twobarks.com/
Reply With Quote
  #3 (permalink)  
Old 02-27-2006
Jim Michaels
 
Posts: n/a
Default Re: help - isolate specific xml from mySQL entry?


"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).



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 03:37 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0