Jump to content

How do a look for a word within a string?


Recommended Posts

I want to look for the word "pant" within this string: "Pants: I'm going to be late!"


How would I do this?


I'd prefer it if I wasn't case sensitive search!


This is how I'm trying to do it at the moment but it's not working!


$status = "Pants: I'm going to be late!";


$changeValue = strtok($status, " ");

$changeValue = strtolower($changeValue);


$imageValue = "images/";


if($changeValue == "pant:"){ // if I change this value to "pants:" with the colon it works however I only want to search for the word "pant" without the "s" or the ":"

$imageValue .= "pant.PNG";


Link to comment
Share on other sites

stripos is defo the best way of doing it. Thanks buddy.


This was my code for anyone else that was stuck:


if(stripos($changeValue, $string) !== false){

echo "The string contains the value of the string variable!";




And the case-insensitive counterpart to strpos() is stripos.

Edited by Stuart_Westgate
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.