Easy question
Posted: Mon May 07, 2007 9:13 pm
How do I get the first word of a string?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$words = explode(' ', $string);
echo $words[0];Code: Select all
if($InputTextField)
{
$InputTextField = stripslashes($InputTextField); // there might be slashes I don't want
$words = explode(' ', $InputTextField); // converts my string to an array
$IsIt = $words[0]; // I dont know why I need this, I don't think i do
unset($words[0]); // destroys the first word in the array
$IsIt = $words[]; // tries to convert the array back to a string but there's an error!
$InputTextField = $IsIt; // Gives my string back to the original variable for further processing....Code: Select all
if($InputTextField)
{
$InputTextField = stripslashes($InputTextField);
$words = explode(' ', $InputTextField);
$IsIt = $words[0];
unset($words[0]);
$InputTextField = implode(" ", $words);To bad for you, you just used the solution JCart gave you, this not only makes you look stupid but in my opinion calls for an apology from you to jcart he is just trying to help you but if you are to ignorant to take his aid you should look for another forum to help you and put up with your ignorant and rude behavior.ChessclubFriend wrote:lucky for your sorry looking ego, I found the solution myself
Code: Select all
if($InputTextField) { $InputTextField = stripslashes($InputTextField); $words = explode(' ', $InputTextField); $IsIt = $words[0]; unset($words[0]); $InputTextField = implode(" ", $words);
Next time you break a rule, you banned. Nobody here has to put up with your insults... and don't expect me to ever help you again.[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.3 wrote:15. A wide variety of opinions may be expressed on this public discussion forum. Respect positions which differ from your own. We like to see a vigorous intellectual discussion which proceeds politely and addresses the technical merits of different positions. Do not expect that anyone will alter their opinion of a topic regardless of however logical you believe your argument to be. Do not attack anyone personally for whatever reason - doing so contravenes the spirit in which this forum was founded and can have serious consequences.