litebearer Posted February 3, 2011 Share Posted February 3, 2011 Scenario: 1) have a string which I explode into an array using the space as delimiter. 2) display the array using print_r as well as var_dump (have also encased print_r with <pre>) The issue is both do NOT show the content OR list the key/content for some of the elements. Yet when I implode the array using the space as delimiter, all is well as far as the functioning of the string. Why? the code: $string1 = '"<IMG src="http://nstoia.com/sat/disp_pag/images/becky_nick.jpg" width="100" height="200">'; $string2_array = explode(" ", $string1); echo "<PRE>"; print_r($string2_array); echo "</pre>"; $string3 = implode(" ", $string2_array); echo $string3; the output (note: element 0 is missing the <IMG and element 1 is missing in its entirety) Array ( [0] => " src="http://nstoia.com/sat/disp_pag/images/becky_nick.jpg" [2] => width="100" [3] => height="200"> ) I suspect it may have something to do with the < at the start, yet the > at the end is retained and shown. I can 'work around it'; however, it would be nice to know why it does what it does. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/226591-confused-about-result-of-explode/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 3, 2011 Share Posted February 3, 2011 If you do a 'view source' of the print_r() output, you will see why you are seeing the results that you are. Quote Link to comment https://forums.phpfreaks.com/topic/226591-confused-about-result-of-explode/#findComment-1169499 Share on other sites More sharing options...
MatthewJ Posted February 3, 2011 Share Posted February 3, 2011 Like PFMaBiSmAd said... in the source it is correct, also the leading double quote seems useless Quote Link to comment https://forums.phpfreaks.com/topic/226591-confused-about-result-of-explode/#findComment-1169501 Share on other sites More sharing options...
litebearer Posted February 3, 2011 Author Share Posted February 3, 2011 Thank you. Its seems it is the result of the 'real' first element containing an 'unbalanced' double quote. Makes sense. Thank you, again. Quote Link to comment https://forums.phpfreaks.com/topic/226591-confused-about-result-of-explode/#findComment-1169504 Share on other sites More sharing options...
litebearer Posted February 3, 2011 Author Share Posted February 3, 2011 Matt.. Yep! I got carried away trying to keep track of single and double quotes. Just sloppiness on my part, can't blame bleary eyes today. Hmmm maybe temps in the single digits??? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/226591-confused-about-result-of-explode/#findComment-1169507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.