Breaking down strings in php | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 šŸ˜€

27th Apr 2017, 4:37 PM
Mashan Shaluka1
Mashan Shaluka1 - avatar
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"; } }
27th Apr 2017, 4:55 PM
ā©ā–¶Clauā—€āŖ
ā©ā–¶Clauā—€āŖ - avatar
+ 3
Make sure that your delimiter is a space and not an empty string.
27th Apr 2017, 5:17 PM
CHMD
CHMD - avatar
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()
27th Apr 2017, 5:05 PM
Mashan Shaluka1
Mashan Shaluka1 - avatar
0
@kingdx works now šŸ˜ƒ does explode break down the to words?
27th Apr 2017, 5:28 PM
Mashan Shaluka1
Mashan Shaluka1 - avatar