[ PHP ] How do I select a word from a string?
#1

Hello. I have sentence "Lunoxx sold a car.".
I just select "Lunoxx" and "car", how can I do this?

Thanks ! Sorry for my bad english
Reply
#2

I am not sure what you exactly want, do you want a function get fetch a specific word of the sentence ?

Either way you could use sscanf like that
pawn Код:
new word1[32], word2[32];
sscanf("Lunoxx sold a car", "s{ss}s", word1, word2);
Reply
#3

Yes, but I want it in PHP.
Reply
#4

You can use split.
PHP код:
$testString "Lunoxx sold a car."//Set the string to a test.
$splitText explode(' '$testString); //Now the actual code to split it from spaces.

//Now use it.
echo $splitText[0]; //Will print "Lunoxx" 
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)