+ 1
Breaking down strings in php
A string contains (n) amount of words letters or symbols.The string contains data inserted by the user. Can I break down the string and search for a specific word, phrase or symbol in the string and echo something if the the user has typed what I was searching for. If there is a way please explain. Thanks 😀
4 Respostas
+ 3
try this:
$string = "this is a sample string";
$arr = explode(' ' , $string);
foreach ( $arr as $elem ){
if ( $elem == "sample" ) {
echo "ok, is just a sample";
}
}
+ 3
Make sure that your delimiter is a space and not an empty string.
0
@Claudio Vidal
I copied the exact code above but it does not seem to work.
errors: explode() : empty delimiter
invalid argument supplied for forearch()
0
@kingdx works now 😃
does explode break down the to words?