| | |
Search for a string in a variable---
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Search for a string in a variable---
Is there a way to find a particular string in php.
For example:
I want php to echo "Found" if the word "sports" in found in this url http://yahoo.com/sports/soccer/index.html
if not then it should echo "bad Luck"
Is there any pre-defined function for this in php?
Thanx
Is there a way to find a particular string in php.
For example:
I want php to echo "Found" if the word "sports" in found in this url http://yahoo.com/sports/soccer/index.html
if not then it should echo "bad Luck"
Is there any pre-defined function for this in php?
Thanx
preg_match sounds like what you want.
More info can be found here:
http://us2.php.net/manual/en/function.preg-match.php
Good luck!
More info can be found here:
http://us2.php.net/manual/en/function.preg-match.php
Good luck!
I NEED AN ADULT!
•
•
•
•
preg_match sounds like what you want.
More info can be found here:
http://us2.php.net/manual/en/function.preg-match.php
Good luck!
However, if you're going to look for just a string, then you should use a function such as strstr() or stristr()
eg: case sensitive
[PHP]
if (strstr('http://example.com/sports.ext', 'sports')) {
echo 'found';
} else {
echo 'not found';
}[/PHP]
preg_match() is much slower than strstr() and also uses more resources as it matches a pattern.
Last edited by digital-ether; May 11th, 2007 at 8:09 am.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Parse a concatenated variable and string? (PHP)
- Search and count for string (C)
- Dynamic Query (JSP)
- Problem with string variable in void prnt function (C++)
- wordcount (Java)
- "String class" (Java)
- File Saving / Reading - Non Constant Folder? Help needed (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: ugh.. silly script
- Next Thread: Bit of a language dilemna
| Thread Tools | Search this Thread |
5.2.10 action apache api array beginner beneath binary broken cakephp checkbox class classes cms code cron curl database date destroy display dynamic echo echo$_get[x]changingitintovariable... email encode error fcc file files folder form forms function functions google header howtowriteathesis href htaccess html image images include insert ip javascript joomla limit link local login mail memberships menu mlm mod_rewrite multiple multipletables mysql mysqlquery neutrality oop open passwords paypal pdf php provider query radio random record remote rss script search server sessions sockets source space sql strip_tags syntax system table template thesishelp tutorial update upload url validator variable video voteup web window.onbeforeunload=closeme; youtube






