Hey yaaaaaaa guys n gals!
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:hous e:gate:tent
candy:lollipop: choco:street:ch ild
i want to search the word 'tree' wich I take from the user dynamically.
when I use the following code:
[CODE=PHP]
if (isset($_POST['findtag']))
{
$tags = $_POST['txttags'];
$result = mysql_query("se lect tags from tags") or die("MYSQL Returned: " . mysql_error());
while($row = mysql_fetch_ass oc($result))
{
$temptag=$row['tags'];
$strr2 = strstr($temptag , $tags);
echo "$strr2"."< br />";
}
}
[/CODE]
I get the output as:
tree:sweet:hous e:gate:tent
tree
here,
the last line of the output for the searched criteria('tree' ) obviously comes from
'street' in 'candy:lollipop :choco:street:c hild'
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.
thaaaaaaaaaaaan ks in advance!!!
if there's a better way in PHP to do this please let me know.
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:hous e:gate:tent
candy:lollipop: choco:street:ch ild
i want to search the word 'tree' wich I take from the user dynamically.
when I use the following code:
[CODE=PHP]
if (isset($_POST['findtag']))
{
$tags = $_POST['txttags'];
$result = mysql_query("se lect tags from tags") or die("MYSQL Returned: " . mysql_error());
while($row = mysql_fetch_ass oc($result))
{
$temptag=$row['tags'];
$strr2 = strstr($temptag , $tags);
echo "$strr2"."< br />";
}
}
[/CODE]
I get the output as:
tree:sweet:hous e:gate:tent
tree
here,
the last line of the output for the searched criteria('tree' ) obviously comes from
'street' in 'candy:lollipop :choco:street:c hild'
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.
thaaaaaaaaaaaan ks in advance!!!
if there's a better way in PHP to do this please let me know.
Comment