I want to know how I can match a whole word within a string using php.
these are the results returned by the mysql query:
tree:sweet:house:gate:tent
candy:lollipop:choco:street:child
i want to search the word 'tree' wich I take from the user dynamically.
when I use the following code:
Expand|Select|Wrap|Line Numbers
- if (isset($_POST['findtag']))
- {
- $tags = $_POST['txttags'];
- $result = mysql_query("select tags from tags") or die("MYSQL Returned: " . mysql_error());
- while($row = mysql_fetch_assoc($result))
- {
- $temptag=$row['tags'];
- $strr2 = strstr($temptag, $tags);
- echo "$strr2"."<br />";
- }
- }
tree:sweet:house:gate:tent
tree
here,
the last line of the output for the searched criteria('tree') obviously comes from
'street' in 'candy:lollipop:choco:street:child'
but I want to view only data rows that has the whole word 'tree'
what im trying to do is allow users to use tags to search for a image.
tags fro an image is stored in a single field in a during uploading time (done by administrator) seperated by a delimeter.
thaaaaaaaaaaaanks in advance!!!
if there's a better way in PHP to do this please let me know.