Looking for a specific function...

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
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Looking for a specific function...

Post by JellyFish »

I'm looking for a function that can allow me to look for a string within a string but has to be in between the ",".

Example:

Code: Select all

the_function("the long long long string", "long");
Example 2:

Code: Select all

$the_longstring = "this is the long string, that, has commas.";
$the_keyword = "that";

the_fonction($the_longstring, $the_keyword);
As you can see I'm going to make a search engine for my site and I need to be able to use the keywords (the input typed in the search bar) and the information in the keywords field in the database,each comma seperated, to allow it to work.

If there is any better way of doing this I'm allways open to suggestions. :)

Thanks and all help is appreciated.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I'm not 100% what you're asking. Do you want to break the strig apart where all the commas are? That's just explode() ;)

If you're saying you want the part between the commas you'll need a regular expression or a series of statements to process the result of an explode().

Take a look at the stickies in the regex forum on this board... ask if you get stuck :)
namitjung
Forum Commoner
Posts: 42
Joined: Mon Jun 20, 2005 3:17 am

Post by namitjung »

use

Code: Select all

substr()
function
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

sounds like you'll need to use a regular expression
Post Reply