Forum Moderators: coopster

Message Too Old, No Replies

Help: regex() how? feeling helpless

         

clown

2:54 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



even tho i know that these cahrs is the one i want, I just dont manage to add them to the regex()

This is the result of me trying out regex..hehe (don't laugh ;D)
regex('[a-åA-Å0-9]\[,._-]', $message);

can anyone help me getting the regex() to work?

Thanks In Advance
Regards,
Clown

camilord

2:58 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



i'm not good in reg expression too [ don't laugh too ].. but isn't eregi() or ereg() or preg_match you will be using?

clown

3:01 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



is it? what's the differense between them? all i want is to check the $message that it only includes chars between a-å both lower and uppercase, and also numbers 0-9

btw: å is anorwegian letter, last one in our alphabet.

camilord

3:10 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



<?php

$expression = "/å¦Å/i";

if (preg_match ($expression, $message))
{
print "has the last alphabet of you country";
} else {
print "no last alphabet of you country";
}

?>

[edited by: coopster at 7:53 pm (utc) on April 9, 2007]
[edit reason] no urls please TOS [webmasterworld.com] [/edit]

dreamcatcher

3:10 pm on Apr 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi clown,

Have you looked at the PHP website for a better understanding of some of the regex functions?

[uk.php.net...]

dc

clown

3:14 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



camilord:
so i can just continue with something like "/å¦Å/[a-Å]/[0-9]/i";?

dreamcatcher:
yeah, i've been reading there and on, docforge.com & regexlib.com... i'm still clueless...hehe... u see, i have a type of readingdisorder =) i kinda need to see the code... not the whole code (i'm not stupid) all i need is a guidline... i just cant process lot's of theoretical content at the same time =)

sounds weird eh since i'm learning PHP haha =) dunno why, but somhow it works out =)

[edited by: clown at 3:16 pm (utc) on April 9, 2007]

camilord

3:15 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



<?php
$expression = "/(å¦Å)[a-zA-Z]/i";

if (preg_match($expression, $message))
{
print "has the last alphabet of your country";
} else {
print "no last alphabet of your country";
}

?>

or this might work too.... :)

clown

3:18 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



ok.. but there's 2 other letters in our alphabet that i need to check for .. that's æÆ øØ

so should i do something like this?
"/(å¦Å)/(æ¦Æ)/(ø¦Ø)[a-zA-Z]/i";

clown

3:23 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



i used this code:
<?php

$message = "hei på deg! skjærer du brød?";
$expression = "/(å¦Å)/(æ¦Æ)/(ø¦Ø)/[a-zA-Z]/i";

if (preg_match($expression, $message))
{
print "has the last alphabet of your country";
} else {
print "no last alphabet of your country";
}

?>

and got this:
Warning: preg_match(): Unknown modifier '(' in /var/www/00/43/75/example.com/www/phpschool/test/misc/ereg.php on line 15

Line 15: if (preg_match($expression, $message))

[edited by: eelixduppy at 6:30 pm (utc) on April 9, 2007]
[edit reason] exemplified error [/edit]

camilord

3:32 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



<?php

$message = "hei på deg! skjærer du brød?";
$expression = "/[å¦Å]¦[æ¦Æ]¦[ø¦Ø][a-zA-Z]/i";

if (preg_match($expression, $message))
{
print "has the last alphabet of your country";
} else {
print "no last alphabet of your country";
}

/*
it works for me... i guess this is what you looking for..
*/

?>

camilord

3:35 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



<?
$message = "hei på deg! skjærer du brød?";
$expression = "/[å¦Å]¦[æ¦Æ]¦[ø¦Ø][a-zA-Z]/i";

if (preg_match($expression, $message))
{
print "has the last alphabet of your country";
} else {
print "no last alphabet of your country";
}
?>

if you are copying my example right into your editor, try to replace the ¦ with the logical OR in you keyboard.. i mean, retype it again.. coz i think webmaster worlds re-encode this character...

clown

3:37 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



yeah kinda... if that can block the $message from containing "bad" characters like slashes \ single quotes', HTML tags <> etc that might be abused by a user to mess up my site like inserting a meta tag that redirects every visitors to another site etc

camilord

4:06 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



use htmlentities() function

and stripslashes()

camilord

4:07 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



<?
$message = "hei på deg! skjærer du brød?";
$expression = "/[å¦Å]¦[æ¦Æ]¦[ø¦Ø][a-zA-Z]/i";

$message = htmlentities($message);
$message = stripslashes($message);

if (preg_match($expression, $message))
{
print "has the last alphabet of your country";
} else {
print "no last alphabet of your country";
}
?>

or use [ kses ], try to search in google...

clown

4:10 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



htmlenteties() will just replace the <> with $lt; &gt;.. i want the whole processing to stop, if any "illegal" chars is in the message.. hehe... i'm beeing a pain in the ass aint i? ;D

basicly the message is going to be validated the same way as an email using that regex() or whatever it was...

Email validation -> if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {

camilord

4:18 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



actually i uses KSES for this kind of problem... to filter the unwanted/illegal characters that might mess-up out websites...

and why don't you apply text editor for you textarea? it would be nice... :)

[edited by: eelixduppy at 6:32 pm (utc) on April 9, 2007]

camilord

4:21 pm on Apr 9, 2007 (gmt 0)

10+ Year Member



clown, got to go... (got to sleep... its 1:18AM already here in the philippines..)

cheers...

i sign up in your shoutbox in ur website.. nice site.. :bow:

[edited by: eelixduppy at 6:34 pm (utc) on April 9, 2007]