[ PHP ] How do I select a word from a string? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [ PHP ] How do I select a word from a string? (
/showthread.php?tid=591135)
[ PHP ] How do I select a word from a string? -
Lunoxel - 08.10.2015
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
AW: [ PHP ] How do I select a word from a string? -
Nero_3D - 08.10.2015
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);
Re: [ PHP ] How do I select a word from a string? -
Lunoxel - 08.10.2015
Yes, but I want it in PHP.
Re: [ PHP ] How do I select a word from a string? -
Ahmad45123 - 08.10.2015
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"