Jump to content

Confused about result of explode


litebearer

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/226591-confused-about-result-of-explode/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.