| | |
Split a string into two parts?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Simply use the explod function to convert the string into an array. So for your example, the following code would apply:
php Syntax (Toggle Plain Text)
$string="hyderabad,india"; $strings=explode(',',$string); echo $strings[0]; // outputs: hyderabad echo "<br>"; // new line echo $strings[1]; // outputs: india
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Aug 2008
Posts: 149
Reputation:
Solved Threads: 6
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........
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........
My best wishes ... from my soul ... for everyone!
Keep Smiling....Never Depress
Keep Smiling....Never Depress
Try the following to match the 2:
php Syntax (Toggle Plain Text)
$input='bluefox'; $database_input='Blue Fox'; if (str_replace(' ','',strtolower($input))==str_replace(' ','',strtolower($database_input))) { echo "They match"; }
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
Join Date: Jan 2009
Posts: 60
Reputation:
Solved Threads: 4
Oh, just to throw this in-MySql has a built-in search "help"
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 }.
•
•
•
•
<?
$input = 'blue fox';
$query = mysql_query("SELECT * FROM `table`WHERE `column` LIKE '%$input%'");
while($show = mysql_fetch_assoc($query)) {
echo $show['column'] . "<br .";
}
?>
Last edited by Andrieux; Feb 9th, 2009 at 6:32 pm.
•
•
Join Date: May 2008
Posts: 113
Reputation:
Solved Threads: 4
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
would output BlueBird
and to make it lowercase
would now return bluebird
and the strings would now match
to remove spaces
php Syntax (Toggle Plain Text)
$mysqldata = 'Blue Bird'; $mysqldata = str_replace (" ", "", $mysqldata); echo $mysqldata;
would output BlueBird
and to make it lowercase
php Syntax (Toggle Plain Text)
$mysqldata = strtolower($mysqldata); echo $mysqldata;
would now return bluebird
and the strings would now match
Last edited by peter_budo; May 30th, 2009 at 5:33 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Do you geek alone?
<<TimmCo>> Custom Computers
~Executive
<<TimmCo>> Custom Computers
~Executive
![]() |
Similar Threads
- boost::algorithm::split with string delimeters (C++)
- Parse or Tokenize String (C++)
- encrypt and decrypt query string (VB.NET)
- Help with htaccess (IT Professionals' Lounge)
- splitting a ftp connection string to it's parts (Shell Scripting)
- Program, help (Java)
- breaking up a String... (a bit more advance) (Java)
Other Threads in the PHP Forum
- Previous Thread: Php insert to html
- Next Thread: draw image with bold/italic text
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code confirm cron curl customizableitems database date display dynamic echo email error external fcc file files folder form forms forum freelancing function functions google header headmethod howtowriteathesis href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction menu method mlm mod_rewrite multiple mysql neutrality oop pageing pagerank paypal pdf php phpmysql play problem query question radio random recursion remote root script search select server sessions sms soap source space sql support! syntax system table template tutorial update upload url validator variable video web youtube






