Re: [PHP] Help with regular expressions
On Tue, January 17, 2006 1:54 pm, Carl Furst wrote: > Ok I am so stumped.. I'm doing something stupid and I can't figure it > out.. > > Here's the code: > > > $eml = '[EMAIL PROTECTED] > ceo'; > if (strpos($eml, ' ')) echo "yep, there are spaces\n"; //does strpos > see the > spaces? > echo preg_replace('/\s/', '', $eml); //WTF? Preg_replace does not? > echo "$eml\n"; > > > ?> > > As you can see there are a bunch of spaces in that email address. I'm > trying > to use preg_replace to get rid of them. Strpos sees the spaces and the > first > echo statement is executed. The second echo prints nothing and the > third > prints the original $eml with nothing substituted. > > Can anyone see why the perl reg isn't seeing the spaces? It should "work"... Though I would recommend using \\s instead of \s, because \ is a special character to '' and when I see \s I think you mean something like \n, only not... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with regular expressions
Al wrote: John Nichel wrote: Carl Furst wrote: Ok I am so stumped.. I'm doing something stupid and I can't figure it out.. Here's the code: $eml = '[EMAIL PROTECTED] ceo'; if (strpos($eml, ' ')) echo "yep, there are spaces\n"; //does strpos see the spaces? echo preg_replace('/\s/', '', $eml); //WTF? Preg_replace does not? echo "$eml\n"; ?> As you can see there are a bunch of spaces in that email address. I'm trying to use preg_replace to get rid of them. Strpos sees the spaces and the first echo statement is executed. The second echo prints nothing and the third prints the original $eml with nothing substituted. Can anyone see why the perl reg isn't seeing the spaces? Carl Working fine on my end (copy/pasted your code) $eml= trim($eml); $pattern= "%\s%";//I use % as delimiters, more obvious for me when debugging if(preg_match($pattern, $eml) echo "yep, there are spaces\n"; preg_replace($pattern, '', $eml); echo "works now\n"; Sorry, left off the new $eml $eml= preg_replace($pattern, '', $eml); echo "works now\n"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with regular expressions
I tested this with $t = "string string"; preg_replace('/\s/', '', $t); echo $t; And the replace left a space... so then I tried this $t = "string string"; $t = preg_replace('/\s/', '', $t); echo $t; And the output was spaceless (spaced out?)... maybe worth a try? HTH Dan -- -Original Message- From: Al [mailto:[EMAIL PROTECTED] Sent: 17 January 2006 22:45 To: php-general@lists.php.net Subject: Re: [PHP] Help with regular expressions John Nichel wrote: > Carl Furst wrote: > >> Ok I am so stumped.. I'm doing something stupid and I can't figure it >> out.. >> >> Here's the code: >> >> > >> $eml = '[EMAIL PROTECTED]ceo'; >> if (strpos($eml, ' ')) echo "yep, there are spaces\n"; //does strpos >> see the >> spaces? >> echo preg_replace('/\s/', '', $eml); //WTF? Preg_replace does not? >> echo "$eml\n"; >> >> >> ?> >> >> As you can see there are a bunch of spaces in that email address. I'm >> trying >> to use preg_replace to get rid of them. Strpos sees the spaces and the >> first >> echo statement is executed. The second echo prints nothing and the third >> prints the original $eml with nothing substituted. >> >> Can anyone see why the perl reg isn't seeing the spaces? >> >> Carl >> > > Working fine on my end (copy/pasted your code) > $eml= trim($eml); $pattern= "%\s%"; //I use % as delimiters, more obvious for me when debugging if(preg_match($pattern, $eml) echo "yep, there are spaces\n"; preg_replace($pattern, '', $eml); echo "works now\n"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __ NOD32 1.1369 (20060117) Information __ This message was checked by NOD32 antivirus system. http://www.eset.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with regular expressions
John Nichel wrote: Carl Furst wrote: Ok I am so stumped.. I'm doing something stupid and I can't figure it out.. Here's the code: if (strpos($eml, ' ')) echo "yep, there are spaces\n"; //does strpos see the spaces? echo preg_replace('/\s/', '', $eml); //WTF? Preg_replace does not? echo "$eml\n"; ?> As you can see there are a bunch of spaces in that email address. I'm trying to use preg_replace to get rid of them. Strpos sees the spaces and the first echo statement is executed. The second echo prints nothing and the third prints the original $eml with nothing substituted. Can anyone see why the perl reg isn't seeing the spaces? Carl Working fine on my end (copy/pasted your code) $eml= trim($eml); $pattern= "%\s%"; //I use % as delimiters, more obvious for me when debugging if(preg_match($pattern, $eml) echo "yep, there are spaces\n"; preg_replace($pattern, '', $eml); echo "works now\n"; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with regular expressions
Carl Furst wrote: Ok I am so stumped.. I'm doing something stupid and I can't figure it out.. Here's the code: As you can see there are a bunch of spaces in that email address. I'm trying to use preg_replace to get rid of them. Strpos sees the spaces and the first echo statement is executed. The second echo prints nothing and the third prints the original $eml with nothing substituted. Can anyone see why the perl reg isn't seeing the spaces? Carl Working fine on my end (copy/pasted your code) -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with regular expressions
Ok I am so stumped.. I'm doing something stupid and I can't figure it out.. Here's the code: As you can see there are a bunch of spaces in that email address. I'm trying to use preg_replace to get rid of them. Strpos sees the spaces and the first echo statement is executed. The second echo prints nothing and the third prints the original $eml with nothing substituted. Can anyone see why the perl reg isn't seeing the spaces? Carl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Help with Regular Expressions
> I need to filter out certain characters from being > stored in the database from our signup form. The > fields include first name, last name, street address, > city, zip, etc. > Question 1: What characters should be allowed, other > than lowercase, uppercase, digits, and the space > character? Some names have ' or - in them, same for addresses. > Question 2: What is a regular expression for this? Yes...there is a regular expression for everything. :) Just come up with some functions that filter the input based on a few regex. You can display it with htmlentities() and it'll stop javascript and html from being evaluated. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help with Regular Expressions
I need to filter out certain characters from being stored in the database from our signup form. The fields include first name, last name, street address, city, zip, etc. Question 1: What characters should be allowed, other than lowercase, uppercase, digits, and the space character? Question 2: What is a regular expression for this? My main goal is to filter out chinese and other characters... __ Do you Yahoo!? New DSL Internet Access from SBC & Yahoo! http://sbc.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Help with regular expressions
Daniel, > Hi! I´m new to regular expressions, and it seems to be an art to make it > work as expected. > > I´m trying to remove all "single-line" comments from an string - that´s > everything after "//" to the end of a line. I expected that this would do > the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work. > > Any tips? RegEx can be expensive. Always ask "do I need one?" In this case, use a string find to locate the // and the following \n (or whatever marks the end of line on your/supported OpSys), then substring or string replace. If would be quite interesting to see a performance comparison on this - if you've got time... =dn PS if you were working with alpha-text and had to consider upper and lower case, then things might sound very different! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Help with regular expressions
Sorry, I forgot the newline at the end... your reg ex should look like: //.*\n making your command be: ereg_replace("//.*\n","",$string) Try that ;) Jeff > I think your problem is you are not including whitespace. Also, remember > that . (dot) means any character except newline, so why not try this as your > reg ex: > > //.* > > Hope that helps. > > -Jeff > - Original Message - > From: "José Daniel Ramos Wey" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, January 24, 2002 5:00 PM > Subject: [PHP] Help with regular expressions > > > > Hi! I´m new to regular expressions, and it seems to be an art to make it > > work as expected. > > > > I´m trying to remove all "single-line" comments from an string - that´s > > everything after "//" to the end of a line. I expected that this would do > > the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work. > > > > Any tips? > > > > TIA, > > Daniel Wey > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Help with regular expressions
I think your problem is you are not including whitespace. Also, remember that . (dot) means any character except newline, so why not try this as your reg ex: //.* Hope that helps. -Jeff - Original Message - From: "José Daniel Ramos Wey" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 24, 2002 5:00 PM Subject: [PHP] Help with regular expressions > Hi! I´m new to regular expressions, and it seems to be an art to make it > work as expected. > > I´m trying to remove all "single-line" comments from an string - that´s > everything after "//" to the end of a line. I expected that this would do > the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work. > > Any tips? > > TIA, > Daniel Wey > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Help with regular expressions
Hi! I´m new to regular expressions, and it seems to be an art to make it work as expected. I´m trying to remove all "single-line" comments from an string - that´s everything after "//" to the end of a line. I expected that this would do the job: ereg_replace("//[[:alnum:]]*\n","",$string), but it didn´t work. Any tips? TIA, Daniel Wey -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] HELP with Regular Expressions
I am having a little problem with Regular Expressions In the function below I am trying to make sure only these characters are being used in the hostname. If the hostname contains letters,digits,periods and minus signs then it is fine and we can let the process continue. If it has underscore signs or slashes or anything else in it I what it to give an error. The problem with my function below is it reject everything. What am I doing wrong? if (($hostname) || ($HOSTNAME)) { $hostname= trim($hostname); if ($HOSTNAME) $hostname = trim($HOSTNAME); if (!eregi("^[-a-z0-9-]+(\.[a-z0-9-]+)*$ ", $hostname)) { print_error("your your hostname is invalid"); } $HOSTNAME = $hostname; } Best regards, Richard mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]