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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.