Page 1 of 1

Looking for a specific function...

Posted: Sun Mar 05, 2006 6:41 pm
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.

Posted: Sun Mar 05, 2006 6:47 pm
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 :)

Posted: Sun Mar 05, 2006 10:41 pm
by namitjung
use

Code: Select all

substr()
function

Posted: Sun Mar 05, 2006 10:48 pm
by John Cartwright
sounds like you'll need to use a regular expression