2 quick questions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jackbarnett
Forum Newbie
Posts: 2
Joined: Tue Jul 25, 2006 5:19 pm

2 quick questions

Post 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!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

1. trim()
2. preg_match() (or other php regex function)
jackbarnett
Forum Newbie
Posts: 2
Joined: Tue Jul 25, 2006 5:19 pm

Post by jackbarnett »

THANKS!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

:wink:
Post Reply