FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


How to use tags for search





imagefree
I am working on an Image Gallery System, where a person while uploading an image specifies the related tags like wallpaper, picture, beautiful, natural, mountain etc separated by comma.

Now what i want is a script that separates all such words (may be using explode()), and make them links. For this i need validation too, that no other character than SPACE, COMMA, A-Z, a-z is entered.
Can someone please help me in developing such script!!!!

I already searched on Google, but failed to find the help or a readymade one.

Thanks WAITING for responses.
LukeakaDanish
If you know php it shouldnt be too hard.

Yes, explode would be great for this task. Presumably users entering numbers or symbols is fine - as long as it doesn't interfeer with your HTML or database.

Any, from php.net, here is an example of explode:

Code:
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2


So obviously the first parameter would, in your case, be ", " instead of " ".

Then just add the relevant html to the ends of each string in the array (using a loop ofcourse!) and echo it out.

Good luck.
rvec
Quote:
For this i need validation too, that no other character than SPACE, COMMA, A-Z, a-z is entered.

If those are entered should the script output a warning or replace the characters with something (could even be '')?
Anyhow preg_replace would be the way to go.

Code:
<?php
$string = 'sdfg,rth,sdf,wertgs,sdf,rthrthsw,34tqgfas4,adsfg,.43,w4b';
$array = explode(',',$string);
$pattern = '/([^a-zA-Z ]*)/';

foreach($array as $item){
   $new_item=preg_replace($pattern, '', $item);
   $new_array[] = '<a href="search.php?q='.$new_item.'">'.$new_item.'</a>';
}
?>


That would explode $string, then replace all characters other then A-Za-z and space(not comma cause those are already gone with the explode) by '' (nothing) and put it all in an array called $new_array
Related topics
Meta Tags
URL redirectors and search engines
Add Contextual Search to Your Blog
Search Engine Optimization some Mistakes
MSN Launches 'Search and Win' Contest
how can i see my website on google search
A search to make JS file even smaller-2306byte to 542
FREE SEO - Search Engine Optimization Canada Blog
Meta tags???
Robot.txt and Meta tags
How do I install meta tags on my forum
SEO TACTICS and NO-NOs - True or False?
SECRETS OF SEARCH ENGINES
Meta Description
My new free search engine submission site
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.