- Forums
- PHP
- How To Break Down A Sentence Into Individual Words With Php String
This Page Contains information about How To Break Down A Sentence Into Individual Words With Php String By wallpaperama in category PHP with 1 Replies. [1039], Last Updated: Sat May 18, 2024
wallpaperama
Wed Jun 20, 2007
1 Comments
2478 Visits
today i will teach you how you can break down a whole sentence into separate words.
lets say i have a string called $string and this is how i declared it:
$string = "breaking down sentence into each word array";
well, if i wanted to break it down, i would have to manually do it like this:
$string1 = "breaking";
$string2 = "down ";
$string3 = "sentence ";
$string4 = "into ";
$string5 = "each ";
$string6 = "word ";
$string7 = "array";
oh, boy, there's gotta be an easier way to do this. i have good news for you, yes you can with a PHP function called explode();
here's and example script:
<?
$string = "breaking down sentence into each word array";
$words= explode(" ", $string );
echo $words[0]; // breaking
echo $words[1]; // down
?>
this would be the output:
OUTPUT:
breaking down
search:
Split a string by string
Returns an array of strings, each of which is a substring of string formed by splitting it on boundaries formed by the string delimiter.
explode
(
if you need more information, check out the the documentation at: http://www.php.net/manual/en/function.explode.php
https://www.wallpaperama.com/forums/how-to-break-down-a-sentence-into-individual-words-with-php-string-t1546.html