Hi frnds..

i want to split a string into two parts..

example:

$string="hyderabad,india";

i want to divide this based on , ...

$string1= "hyderabad";
$string2="india";


plz help me asap...how can i get the output above...

Simply use the explod function to convert the string into an array. So for your example, the following code would apply:

$string="hyderabad,india";
$strings=explode(',',$string);
echo $strings[0]; // outputs: hyderabad
echo "<br>"; // new line
echo $strings[1]; // outputs: india

Thank u ...

i have been cleared my doubt by using explode function...
but i have another doubt here...

For searching....
when i comparing my input string with database string, i phase problem with case sensitive and white spaces....
plz give me a suggetion to do this....

ex:

input = "bluefox";

but in my database that word is like "Blue Fox"..........

i need to get results without changing database strings....

Thanks & regards
Saritha........

Try the following to match the 2:

$input='bluefox';
$database_input='Blue Fox';

if (str_replace(' ','',strtolower($input))==str_replace(' ','',strtolower($database_input)))
    {
    echo "They match";
    }

Oh, just to throw this in-MySql has a built-in search "help"

$input = 'blue fox';

$query = mysql_query("SELECT * FROM `table`WHERE  `column` LIKE  '%$input%'");

while($show = mysql_fetch_assoc($query)) {
          echo $show['column'] . "<br .";
}

Of course, you'd want to check if there is anything returned. use mysql_num_rows(); for that. If the value of that equals != 0, then you're good. else { return an error message }.

Hi frnds....

thanks for all of u...

i think the above all answers are working fine...

you could also take the input from the mysql as a string, trim out the space in between the words and set it as lowercase letters:

to remove spaces

$mysqldata = 'Blue Bird';
$mysqldata = str_replace (" ", "", $mysqldata);
echo $mysqldata;

would output BlueBird

and to make it lowercase

$mysqldata = strtolower($mysqldata);
echo $mysqldata;

would now return bluebird

and the strings would now match

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.