how to search a string

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zerandib
Forum Newbie
Posts: 16
Joined: Tue Dec 16, 2008 12:17 am

how to search a string

Post by zerandib »

Hello,

I need to search for a specific string,

like this;

$variable1 = "this is the available text. it has a url named http://www.myurl.com/val=12&id=001 and it has more more sentences as well."

what i wants to do is to search for the string "http://www.myurl.com/" and if that available in $variable1, needs to print "ok"

if( ..?.. )
{
echo "ok";
}


need help!
cavemaneca
Forum Commoner
Posts: 59
Joined: Sat Dec 13, 2008 2:16 am

Re: how to search a string

Post by cavemaneca »

User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: how to search a string

Post by pickle »

strpos() is faster.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: how to search a string

Post by novice4eva »

pickle wrote:strpos() is faster.
I read strstr() was faster, i bet that it was given in bold letter in old php manual somewhere :D , it's not there in the latest one !!

Code: Select all

http://www.php.net/strstr
there is the post that suggests the same, by Romuald Brunet. Anyways as i said, i just read it and haven't really checked it, and even if it were, i bet the time diff won't be that significant
Post Reply