Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing a search string

Status
Not open for further replies.

thefid

Programmer
Feb 10, 2005
2
US
Ok guys, I know this has been done many times, yet I currently don't have the code for this issue.

Problem: I wish to parse a search string and replace all characters of one type betweeen two other characters (of the same type).

For example, in a search engine search string you can place quotes to search for exact wording on a page. I wish to search for the double quote symbol - '"' and replace all space ' ' characters until I reach the second quote symbol (if the 2nd one exists). There may also be more than 2 double quotes in the string.

Does anyone have a good method for doing this? Any help would be appreciated.

Thanks,
THEFID
 
sounds like a job for a regular expression. search php.net for ereg_match or preg_match.

there is also a recent post on this forum where the user wished to extract an email address between "<" and ">" that will provide you with a good idea of some simple regular expression syntax (you are trying to do the same but with double quotes.

once you have the data you want through a regex then have a look at substr_replace to change your spaces into something else. (if you want to make the url safe then there is a rawurlencode in php that might give you what you want).

if you get comfortable with regex syntax you should be able to do the search and replace in one command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top