Page 1 of 1

2 quick questions

Posted: Tue Jul 25, 2006 5:25 pm
by jackbarnett
New to PHP and have a few basic questions.

How do I strip varaiables of their "return" character.
For example if I'm reading in from a text file (1 word per line) the varaiable would look like this:

test\n

(or test^M under windows or whatever).

In perl I can just do a "chomp($var)" and it cleans it up nice and neat. What is the function in PHP to do this?


Also how do I do regex compares in PHP?


For example, in Perl, I could do something like this

Code: Select all

if ($string =~ /\w{1,3}\s\d{2}\s200[5,6]/) {
print ("Found Date: $string\n"); }
Would output:
Found Date: Jul 07 2005

How do I do that in PHP... it doesn't have the =~ or !~ expressions?!?

Thanks!

Posted: Tue Jul 25, 2006 5:29 pm
by Luke
1. trim()
2. preg_match() (or other php regex function)

Posted: Tue Jul 25, 2006 5:38 pm
by jackbarnett
THANKS!

Posted: Tue Jul 25, 2006 6:00 pm
by Luke
:wink: