Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-07-2012, 08:15 PM   PM User | #1
doubledee
Regular Coder

 
doubledee's Avatar
 
Join Date: Mar 2011
Location: Arizona
Posts: 617
Thanks: 19
Thanked 0 Times in 0 Posts
doubledee has a little shameless behaviour in the past
Some PHP-Regex Questions

Below is a PHP Regex that someone helped me create...

PHP Code:
    if (preg_match_all('/\\{url=([a-zA-Z0-9-]+)\\}/'$body$matchesPREG_SET_ORDER) !== false){ 

Questions:
1.) Why are there double back-slashes before the left and right braces?

2.) How would I change this to say, "Match all instances where the vakue in between the Curly Braces is a Lower-Case Letter, Upper-Case Letter, Number, or Hyphen and is between 2 and 20 characters in length"??

3.) How would I modify this Regex to look for references to images in my "Article Body", where an Image could be either a PNG, JPEG, JPG or GIF?

Here is my best guess...
PHP Code:
    if (preg_match_all('/\\{img=([a-zA-Z0-9-]+)[.png|.jpeg|.jpg|.gif]\\}/'$body$matchesPREG_SET_ORDER) !== false){ 
Thanks,


Debbie
doubledee is offline   Reply With Quote
Old 10-08-2012, 10:28 AM   PM User | #2
Dormilich
Senior Coder

 
Dormilich's Avatar
 
Join Date: Jan 2010
Location: Behind the Wall
Posts: 2,882
Thanks: 9
Thanked 291 Times in 287 Posts
Dormilich is on a distinguished road
1) backslashes are escape characters. if you want a literal backslash, you have to escape that one too

2) {2,20}

3) does your guess work?
__________________
please post your code wrapped in [CODE] [/CODE] tags
Dormilich is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 07:50 AM.


Advertisement
Log in to turn off these ads.