phpBB2Refugees.com Logo
Not affiliated with or endorsed by the phpBB Group

Register •  Login 

Continue the legacy...

Welcome to all phpBB2 Refugees!Wave Smilie

This site is intended to continue support for the legacy 2.x line of the phpBB2 bulletin board package. If you are a fan of phpBB2, please, by all means register, post, and help us out by offering your suggestions. We are primarily a community and support network. Our secondary goal is to provide a phpBB2 MOD Author and Styles area.

Preg_match_all Regular Expression Check


 
Search this topic... | Search phpBB2 Discussion... | Search Box
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Author Message
JLA
Board Member



Joined: 30 Apr 2009

Posts: 310
Location: U.S.A


flag
PostPosted: Tue May 14, 2013 11:24 pm 
Post subject: Preg_match_all Regular Expression Check

Was hoping another couple sets of eyes could take a look at this REGEX and see if something is missing

Code:
$pattern = '`.*?((http)://[\w#$&+,\/:;=?@.-]+.jpg)[^\w#$&+,\/:;=?@.-]*?`i';


Would be running a preg_match_all against that.

_________________
http://www.jlaforums.com
Back to top
StarWolf3000
Board Member



Joined: 10 Jun 2010

Posts: 100
Location: Germany


flag
PostPosted: Wed May 15, 2013 10:10 am 
Post subject: Re: Preg_match_all Regular Expression Check

The chars ?$+ and . need to be escaped to \? \$ \+ and \. if they are part of the string to be checked inside the URL:
Code:
$pattern = '`.*?((http)://[\w#\$&\+,\/:;=\?@\.-]+\.jpg)[^\w#\$&\+,\/:;=\?@\.-]*?`i';
Back to top
JLA
Board Member



Joined: 30 Apr 2009

Posts: 310
Location: U.S.A


flag
PostPosted: Wed May 15, 2013 3:52 pm 
Post subject: Re: Preg_match_all Regular Expression Check

StarWolf3000 wrote:
The chars ?$+ and . need to be escaped to \? \$ \+ and \. if they are part of the string to be checked inside the URL:
Code:
$pattern = '`.*?((http)://[\w#\$&\+,\/:;=\?@\.-]+\.jpg)[^\w#\$&\+,\/:;=\?@\.-]*?`i';


What we are trying to do is pull out all full image URLs out of a string

Code:

$string = "blah blah blah http://www.test.com/test.jpg blah blah blah yada yada yada http://www.testing.com/image/testing.png blah6746uj4j4666j446j7j hahahahahaha www.test.com/test/funky.jpg 535y35yh35h3 blah blah http://testers.com/testing/test.jpg";

$pattern = '`.*?((http)://[\w#$&+,\/:;=?@.-]+.jpg)[^\w#$&+,\/:;=?@.-]*?`i';

if (preg_match_all($pattern,$string,$pics))
{
$picture1 = $pics[1][0];
$pictures2 = $pics[1][1];
$picture3 = $pics[1][2];
}


Current understanding that this (as written) would currently pull the (2) .jpg urls out of $string that start with http. it would not pull the 1 url that only starts with www and ends with jpg nor the png image url that starts with http://. It would take the (2) .jpg urls and assign them to $pictures1 and $pictures2. Does this seem correct?

_________________
http://www.jlaforums.com
Back to top
Display posts from previous:   
Register or Login to Post    Index » phpBB2 Discussion  Previous TopicPrint TopicNext Topic
Page 1 of 1 All times are GMT
 
Jump to:  

Index • About • FAQ • Rules • Privacy • Search •  Register •  Login 
Not affiliated with or endorsed by the phpBB Group
Powered by phpBB2 © phpBB Group
Generated in 0.0261 seconds using 15 queries. (SQL 0.0018 Parse 0.0008 Other 0.0235)
phpBB Customizations by the phpBBDoctor.com
Template Design by DeLFlo and MomentsOfLight.com Moments of Light Logo