Hi ,
is there any nice way to split an string after " " or . ?
Like
$string = "test.test" result = test
$string = "test doe" result = test
Sure i can use explode two times, but I am sure thats not the best solutions ;)
Hi ,
is there any nice way to split an string after " " or . ?
Like
$string = "test.test" result = test
$string = "test doe" result = test
Sure i can use explode two times, but I am sure thats not the best solutions ;)
If you want to split on several different chars, take a look at preg_split
//split string on space or period:
$split=preg_split('/[ \.]/', $string);
You could do a strtr of . into space and then explode by space. Since strtr is very fast.
You want the strtok
function. The manual gives this example:
<?php
$string = "This is\tan example\nstring";
/* Use tab and newline as tokenizing characters as well */
$tok = strtok($string, " \n\t");
while ($tok !== false) {
echo "Word=$tok<br />";
$tok = strtok(" \n\t");
}
?>
Though in your case I suspect that using explode
twice is easier and looks better.