REGEX CHECK WORDPRESS TAGS

posted by Subzero on 2009-07-22 14:41:13
Hi, sorry for my bad english, my question is:
i riceve a tags from post: $tags = $_POST['tags']; //Es: gossip, culture, internet, (the tags of wordpress)
and I would find them with the regex, but that should not exceed 7 words, that is, for example tags1, tags2, tags3, tags4, tags5, tags6, tags7 and stop, if there is tags7 I must leave an error.
my code is:
	$tags = $_POST['tags'];
        if( !preg_match( "/([a-zA-Z0-9\-\_ ]+,){1,7}/s", $tags)){
          echo('<noscript>Errore: Tags non validi oppure maggiori di 7!</noscript><script language="JavaScript">alert("Errore: Tags non validi oppure maggiori di 7!");location.href=\'<a href="http://www.mysite.it\';" rel="nofollow" target="_blank">http://www.mysite.it\';</a></script>');
          die();
        } else {
           $tags = htmlspecialchars($_POST['tags']);
        }
but when I surpass even one tags me it onto the same ...
Thanks
web10
0
Hello,
Why do you want to use regex? You could use explode(), example:
 
$tags = $_POST['tags'];
 
if (count(explode("," $tags, 8))>7){
    echo('<noscript>Errore: Tags non validi oppure maggiori di 7!</noscript><script language="JavaScript">alert("Errore: Tags non validi oppure maggiori di 7!");location.href=\'<a href="<a href="http://www.mysite.it\';"" rel="nofollow" target="_blank">http://www.mysite.it\';"</a> rel="nofollow" target="_blank"><a href="http://www.mysite.it\';" rel="nofollow" target="_blank">http://www.mysite.it\';</a></a></script>');
    exit();
}
else
    $tags = htmlspecialchars($tags);
 
Tell me if it's good for you!
Bye
5 answers - 8 questions
  Positive        Negative

Subzero avatar
Subzero
0
i have a error: Parse error: syntax error, unexpected T_VARIABLE in /membri/socialgeeks/wp-content/themes/prologue/index.php on line 22
in line 22 there is:
if (count(explode("," $tags, 8))>7){
7 answers - 3 questions
  Positive        Negative

Subzero avatar
Subzero
0
i have correct is for ,
if (count(explode(",", $tags, 8))>7){
but now i have an other error in other line:
Parse error: syntax error, unexpected ',' in /membri/socialgeeks/wp-content/themes/prologue/index.php on line 31
if ( "/(http|https)(\:\/\/www.|\:\/\/)([a-zA-Z0-9\_\-\&\%\.\/\?\=]*)/s", $link){
is for check the url :P
7 answers - 3 questions
  Positive        Negative

Subzero avatar
Subzero
0
ok, you were great, the code works perfectly, and I solved the second problem;)
if( preg_match( "/(http\:\/\/|http\:\/\/www\.)[a-zA-Z0-9\_\-\&\%\.\/\?\=]*/s", $link)){
7 answers - 3 questions
  Positive        Negative

web10
0
:-)
Ops sorry, I forgot a comma:
 
if (count(explode(",", $tags, 8))>7){
....
}
 
If you have any other problem, create a new question.
Bye
5 answers - 8 questions
  Positive        Negative



Answer the question



Top Users
  • dail (12)
  • livin52 (3)
  • camu (3)
  • softweb (2)
  • Nadine (1)
  • Josware (1)
  • lfelipecr (1)
  • gregoriohc (1)
  • Mitu (1)
  • ryan714 (1)