Jump to content

splitting string


spillage

Recommended Posts

This is probally more of a Monday morning question.

 

Just running through my book on using the split function with regular expressions.

 

Using

<?php

$email = "[email protected]£49";

$arr=split ('\.|\@|\£', $email);

while (list($key, $value)= each ($arr))

echo '|'.$value;

?>-

 

But the 45 is shown as 49-.

 

Have spent a while looking on google etc. But should it not show 40???

 

I'm sure you can tell I'm fairly new to this so if this is a daft question please dont give me

to much of a verbal hammering.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/101531-splitting-string/
Share on other sites

What "45"? You don't have a 45 in your string. The "-" is showing because you have a "-" after your PHP block and the browser treats that as text to be output to the screen.

 

Also, if you just want to separate the items in the $arr array with "|", you can use the implode() function:

<?php
$email = "[email protected]£49";
$arr=split ('\.|\@|\£', $email);
echo '|' . implode('|',split ('\.|\@|\£', $email));
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/101531-splitting-string/#findComment-519336
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.