| | |
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.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
•
•
Join Date: Aug 2008
Posts: 159
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.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
•
•
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 |
Tag cloud for PHP
.htaccess access ajax apache api array autosuggest beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email emptydisplayvalue error explodefunction file files folder form forms function functions google hack href htaccess html image include insert integration ip java javascript joomla keywords limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search searchbox select server sessions sms soap source space speed sql structure syntax system table tutorial update upload url validation validator variable video web website xml youtube






