php - SimpleXMLElement Cast As String Not Behaving As String -


ok, i'm using simplexml parse rss feeds, , many feeds contain embedded html, i'd able isolate image addresses contained in embedded html. sounds easy enough task, i'm running issue parsing data simplexmlelement objects. here's relevant code.

for($i = 0; $i < count($articles); $i++) {     foreach($articles[$i] $feeddeet) {         $str = (string)$feeddeet;         $result = strpos($str, '"');         if($result === false) {             echo 'there apparently no quotes in string: '.$str;         }         $explodedstring = explode('"', $str);         echo "<br>";         if($explodedstring[0] == $str) {             echo 'explodedstring equal str. apparently, once again, string contains no quotes.';         }         echo "<hr>";     } } 

in situation, $articles array of simplexmlelement objects each representing rss article, , containing many child simplexmlelement objects representing properties , details of article. basically, i'd iterate through properties 1 one, cast them strings, , explode strings using quotes delimiters (because image addresses contained inside of quotes). parse through exploded array , search strings appear image address. however, neither explode() nor strpos() behaving expect to. give example of mean, 1 of outputs of above code follows:

there apparently no quotes in string: <p style="text-align: center;"><img class="alignnone size-full wp-image-243922" alt="gold iphone shop le monde" src="http://media.idownloadblog.com/wp-content/uploads/2013/08/gold-iphone-shop-le-monde.jpg" width="593" height="515" /></p> <p>folks still holding out hope gold iphone rumors aren’t true may want brace themselves, speculation has been confirmed wall street journal-owned blog allthingsd. , given site’s near perfect (perfect?) track record predicting future apple plans, , <a href="http://www.idownloadblog.com/2013/08/16/is-this-apples-gold-colored-iphone-5s/">corroborating evidence</a>, we’d apple indeed going gold…(...)<br/>read rest of <a href="http://www.idownloadblog.com/2013/08/19/allthingsd-gold-iphone-yes/">allthingsd confirms gold iphone coming</a></p> <hr /> <p><small> "<a href="http://www.idownloadblog.com/2013/08/19/allthingsd-gold-iphone-yes/">allthingsd confirms gold iphone coming</a>" article <a href="http://www.idownloadblog.com">idownloadblog.com</a>. <br/>make sure <a href="http://twitter.com/idownloadblog">follow on twitter</a>, <a href="http://www.facebook.com/iphonedownloadblog">facebook</a>, , <a href="https://plus.google.com/u/0/b/111910843959038324995/">google+</a>. </small></p> explodedstring equal str. apparently, once again, string contains no quotes. 

sorry if little hard read, it's copied verbatim output.

as can see, there quotes in string in question, yet, strpos returning false, meaning specified string not found, , explode returning array original string inside, signifying specified delimiter not found. going on here? i've been stumped hours, , feel i'm losing mind.

thanks!

the mistake you've made here debug output html page, messages print being interpreted html browser. see actual contents, either need view page source, or use <pre> tags preserve whitespace, , htmlspecialchars() add layer of html escaping: echo '<pre>' . htmlspecialchars($str) . '</pre>';

if output in browser looks <p style="text-align: center;">, input escaped html-entities, , looks &lt;p style=&quot;text-align: center;&quot;&gt;. although &quot; looks ", not same string, strpos() won't find it.

in order undo layer of escaping, run html_entity_decode() on string before processing it.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -