Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
preg_match pattern issues
Old 12-13-2008, 11:45 AM preg_match pattern issues
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
I'm trying the most basic pattern but it's still failing to produce any matches for me. Can anyone please take a look at the code and let me know what I'm doing wrong. Cheers.

PHP Code:
$pattern "/^[a-z]$/";
$user_name 'frank';
    if(
preg_match($pattern$user_name$match)) {
            return 
true;
    }else{
            return 
false;
    } 
scrobins is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-13-2008, 01:37 PM Re: preg_match pattern issues
Insensus's Avatar
Ultra Talker

Posts: 487
Name: Mark Stegeman
Location: Netherlands, Europe
Trades: 0
I'll explain the pattern for you:
/: denotes the start of a pattern, doesn't really matter much now
^: denotes the start of a subject which kinda means the next character can only be on the start of the string, I think
[a-z]: matches a character in the range a-z, but only one
$: denotes the end of a subject which means the last character should be at the end of the string.

What this means in total, is that your pattern tries if your string has one character in the range a-z that's both at the beginning and end of the string.

What you want is something like this:
PHP Code:
$pattern "/[a-z]*/"
The * makes the last part of the pattern match over and over again until it doesn't match anymore.
__________________
<?php ($helpfull>0)?$talkupation++ : '';?>
Insensus is offline
Reply With Quote
View Public Profile
 
Old 12-13-2008, 10:28 PM Re: preg_match pattern issues
scrobins's Avatar
Skilled Talker

Posts: 50
Name: Stuart Robinson
Location: Busselton
Trades: 0
Cheers for the help. It didn't work initially so I added in the subject characters and it worked like a dream. TA.

PHP Code:
$pattern "/^[a-z]*$/"
scrobins is offline
Reply With Quote
View Public Profile
 
Old 12-15-2008, 04:33 AM Re: preg_match pattern issues
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
/^[a-z]+$/
with asterisk instead of plus sign it will match the empty string also
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to preg_match pattern issues
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61191 seconds with 12 queries