Forum Moderators: coopster

Message Too Old, No Replies

How can I break up a query string

Breaking up a query string using php

         

mack

9:37 am on Feb 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Sorry if this is an obvious one but I just cant figure it out...

I have a script that receives user input from a form. Something like this...

$query=this+is+the+query

What I need to so is break up the entire string so that each word has it's own variable.

$1="this"
$2="is"
$3="the"
$4="query"

etc etc

one problem is the query lenghth will not always be the same.

Is this possible?

Thank you very much in advance.

Mack.

Hester

9:39 am on Feb 10, 2005 (gmt 0)

mack

10:20 am on Feb 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Thanks for the reply :)

I looked at that thread. I was hoping it may have been a little simpler because it doesnt involve the actual url squery will be what is received by the script from the url.

Thanks again.

Mack.

Hester

10:55 am on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps work through the string word by word, splitting it until it returns blank. Use an array with the variable name based on the loop.

coopster

12:36 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have a look at explode() [php.net] mack. I think that may serve the purpose.

Mahoney

9:38 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



$query= "this is the query";
$word = explode(" ", $query);

echo($word[0]);
echo($word[2]);
echo($word[3]);
echo($word[4]);

Hope it helped, had a similar problem yesterday which Hester helped me with. :)

mack

9:28 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



wow awsome, thanks Mahoney

Mack.