Good afternoon guys and girls.
I return with another problem after so long away!
I have a simple search engine on my site. You can see it in action at http://www.didymus.org.uk/tree
My PHP code only works on ONE word. If someone selects a Forename search and enters Paul, the code will return two matches. One for me (my middle name is Paul) and one for my Dad (whose first name is Paul).
But some people are entering things like Kristian Paul on a forename search and although this IS my name, because my search engine works only on one word, no results are returned.
So, enough babble. This is what I need to do.
I want my query.php to strip any spaces AND the characters that follow the spaces leaving just ONE word to search. For example if someone searches for:
Kristian Paul
the code accepts the word Kristian but deletes the space and the word Paul leaving..
Kristian
Sounds simple but I have no idea how to implement this. Have tried the PHP manual but to no avail!
Many thanks in advance.
KD.
PHP Stripping!
Moderator: General Moderators
Re: PHP Stripping!
Code: Select all
list($name) = explode(" ", trim($name));- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP Stripping!
Or:
PHP 5.3:
If not:
PHP 5.3:
Code: Select all
$name = strstr($name, ' ', true);Code: Select all
$name = substr($name, 0, strpos($name, ' '));mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP Stripping!
Weirdan.
Your response was awesomely quick and it worked a treat. Thank you. I was so far off that solution it wasn't even funny!
Thank you again.
KD.
Your response was awesomely quick and it worked a treat. Thank you. I was so far off that solution it wasn't even funny!
Thank you again.
KD.
Re: PHP Stripping!
AbraCadaver.
Nice name. Nice solution. I used list in the end but you managed to achieve what I was trying to achieve using the PHP Manual.
I just couldn't get my head around it!
KD.
Nice name. Nice solution. I used list in the end but you managed to achieve what I was trying to achieve using the PHP Manual.
I just couldn't get my head around it!
KD.