RE: [PHP] preg_match_all question
> -Original Message- > From: Boyd, Todd M. [mailto:tmbo...@ccis.edu] > Sent: Friday, January 16, 2009 2:13 PM > To: php-general@lists.php.net > Subject: RE: [PHP] preg_match_all question > > > -Original Message- > > From: Robert Cummings [mailto:rob...@interjinn.com] > > Sent: Friday, January 16, 2009 4:31 AM > > To: Phil Ewington - iModel Ltd. > > Cc: php-general@lists.php.net > > Subject: Re: [PHP] preg_match_all question > > > > On Fri, 2009-01-16 at 09:42 +, Phil Ewington - iModel Ltd. wrote: > > > Hi All, > > > > > > Having an issue with regular expressions, never been my strong > point! > > > > > > The following pattern only picks up one instance per line, if more > > than > > > one instance exists all text from first {{ to last }} is included, > > can > > > anyone point out where I am going wrong? > > > > > > preg_match_all("/\{\{lang:(.*)\}\}/", $str, $tags); > > > > You need the ungreedy modifier: > > > > preg_match_all("/\{\{lang:(.*)\}\}/U", $str, $tags); > > FWIW, you can tell just the .* to be un-greedy using a ? like so: > > preg_match_all('/\{\{lang:(.*?)\|\|/', $str, $tags); Correction: preg_match_all('/\{\{lang:(.*?)\}\}/', $str, $tags); ...turned my squiggly brackets into pipe chars in a fit of randomness. // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match_all question
> -Original Message- > From: Robert Cummings [mailto:rob...@interjinn.com] > Sent: Friday, January 16, 2009 4:31 AM > To: Phil Ewington - iModel Ltd. > Cc: php-general@lists.php.net > Subject: Re: [PHP] preg_match_all question > > On Fri, 2009-01-16 at 09:42 +, Phil Ewington - iModel Ltd. wrote: > > Hi All, > > > > Having an issue with regular expressions, never been my strong point! > > > > The following pattern only picks up one instance per line, if more > than > > one instance exists all text from first {{ to last }} is included, > can > > anyone point out where I am going wrong? > > > > preg_match_all("/\{\{lang:(.*)\}\}/", $str, $tags); > > You need the ungreedy modifier: > > preg_match_all("/\{\{lang:(.*)\}\}/U", $str, $tags); FWIW, you can tell just the .* to be un-greedy using a ? like so: preg_match_all('/\{\{lang:(.*?)\|\|/', $str, $tags); // Todd -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all question
Robert Cummings wrote: On Fri, 2009-01-16 at 09:42 +, Phil Ewington - iModel Ltd. wrote: Hi All, Having an issue with regular expressions, never been my strong point! The following pattern only picks up one instance per line, if more than one instance exists all text from first {{ to last }} is included, can anyone point out where I am going wrong? preg_match_all("/\{\{lang:(.*)\}\}/", $str, $tags); You need the ungreedy modifier: preg_match_all("/\{\{lang:(.*)\}\}/U", $str, $tags); Cheers, Rob. Rob you're a star, thanks mate. - Phil -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all question
On Fri, 2009-01-16 at 09:42 +, Phil Ewington - iModel Ltd. wrote: > Hi All, > > Having an issue with regular expressions, never been my strong point! > > The following pattern only picks up one instance per line, if more than > one instance exists all text from first {{ to last }} is included, can > anyone point out where I am going wrong? > > preg_match_all("/\{\{lang:(.*)\}\}/", $str, $tags); You need the ungreedy modifier: preg_match_all("/\{\{lang:(.*)\}\}/U", $str, $tags); Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all question
Hi All, Having an issue with regular expressions, never been my strong point! The following pattern only picks up one instance per line, if more than one instance exists all text from first {{ to last }} is included, can anyone point out where I am going wrong? preg_match_all("/\{\{lang:(.*)\}\}/", $str, $tags); Here is an example of what needs to be processed {{lang:PA1Feature1}}{{lang:PA1Feature2}} {{lang:PA2Feature1}}{{lang:PA2Feature2}} TIA Phil. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all nested html text
Do you just wish to remove all the HTML tags from a given string? If so, the strip_tags() function should do this. Ash www.ashleysheridan.co.uk --- Begin Message --- I am trying to get the text between nested html tags within arrays produced by preg_match_all. The simple situation would be: test I want to return 'test'. Assuming $post_results has some string derived from a html page source with lots of nested tags. Replacing new line (seems to be a good idea to do this): $post_results = ereg_replace("[\n\r]", " ", $post_results); I tried this: $pattern = "/<[^>]*>(.+)<\/[^>]*>/i"; Explanation (as far as I understand, please feel free to correct): /.../ start end < - opening html tag [^>] end tag * any number of same end tag - don't understand why needed in addition to above (.+) group: any number of any characters < opening tag \/ literal forward slash [^>] end with tag end * any number of same end tag - don't know why needed again i - modifier, can't remember what it means, something like case insensitive, yes, that would be it //Main expression for first try, substituting tags: preg_match_all($pattern,$post_results,$outputs); //this only replaces the outer tag eg , not the , so: while(stristr($outputs[0][1],"<")) { preg_match_all($pattern,$outputs[0][1],$outputs,PREG_PATTERN_ORDER); } Is there a neat expression to get the inner text withing nested html tags? Thanks, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- End Message --- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all nested html text
I am trying to get the text between nested html tags within arrays produced by preg_match_all. The simple situation would be: test I want to return 'test'. Assuming $post_results has some string derived from a html page source with lots of nested tags. Replacing new line (seems to be a good idea to do this): $post_results = ereg_replace("[\n\r]", " ", $post_results); I tried this: $pattern = "/<[^>]*>(.+)<\/[^>]*>/i"; Explanation (as far as I understand, please feel free to correct): /.../ start end < - opening html tag [^>] end tag * any number of same end tag - don't understand why needed in addition to above (.+) group: any number of any characters < opening tag \/ literal forward slash [^>] end with tag end * any number of same end tag - don't know why needed again i - modifier, can't remember what it means, something like case insensitive, yes, that would be it //Main expression for first try, substituting tags: preg_match_all($pattern,$post_results,$outputs); //this only replaces the outer tag eg , not the , so: while(stristr($outputs[0][1],"<")) { preg_match_all($pattern,$outputs[0][1],$outputs,PREG_PATTERN_ORDER); } Is there a neat expression to get the inner text withing nested html tags? Thanks, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all
On Thu, May 29, 2008 at 8:13 PM, Eric Butera <[EMAIL PROTECTED]> wrote: > Why not use DOMDocument with getElementsByTagName('href') [1] > > http://us2.php.net/manual/en/domdocument.getelementsbytagname.php > Sorry there was an error in that. It felt wrong when I sent it so I looked again. Here is a snippet I'm using on a project right now, so I know it works. ;) $dom = DOMDocument::loadHTML($vo->htmlCopy); foreach ($dom->getElementsByTagName('a') as $node) { if ($node->hasAttribute('href')) { $linkVO = new ...; $linkVO->url= $node->getAttribute('href'); $linkVO->name = $node->nodeValue; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all
On Thu, May 29, 2008 at 2:07 PM, Chris W <[EMAIL PROTECTED]> wrote: > What I want to do is find all links in an html file. I have the pattern > below. It works as long as there is only one link on a line and as long as > the whole link is one line. It seems there should be a way to get this to > work with more than one link on a single line. The work around I have done > for now is to read the whole file into a buffer and remove all new lines and > then add a new line after every closing a tag. Then process each line. > There has to be a better way. > > Any Ideas? Also note I don't want to find any a tags that don't have an > href there probably aren't any but just in case. > > > preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, > PREG_PATTERN_ORDER); > > -- > Chris W > KE5GIX > > "Protect your digital freedom and privacy, eliminate DRM, learn more at > http://www.defectivebydesign.org/what_is_drm"; > > Ham Radio Repeater Database.preg_match_all("/(< > *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, PREG_PATTERN_ORDER); > http://hrrdb.com > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Why not use DOMDocument with getElementsByTagName('href') [1] http://us2.php.net/manual/en/domdocument.getelementsbytagname.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all
On Thu, May 29, 2008 at 01:07:11PM -0500, Chris W wrote: > What I want to do is find all links in an html file. I have the pattern > below. It works as long as there is only one link on a line and as long > as the whole link is one line. It seems there should be a way to get > this to work with more than one link on a single line. The work around > I have done for now is to read the whole file into a buffer and remove > all new lines and then add a new line after every closing a tag. Then > process each line. There has to be a better way. > > Any Ideas? Also note I don't want to find any a tags that don't have an > href there probably aren't any but just in case. > > > preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, > PREG_PATTERN_ORDER); Hi... I have a little function to explode URLs with the following pattern: $str = filename; $pattern = '=^.*]*>(.*).*$=ims'; while (preg_match($pattern, $line, $exploded_url)) { some usefull stuff returns an array ($exploded_url) } $exploded_url[1] = protocoll; $exploded_url[2] = URL; $exploded_url[3] = name of the URL; greetings MG -- -BEGIN GEEK CODE BLOCK- Version: 3.12 GCS/CM d- s++: a+ C>$ UBL*$ P++ L+++ E--- W+++ N+ o-- K- w O- M- V-- PS++ PE++ Y PGP+++ t--- 5 X R++ tv- b+++ DI D G++ e* h r+++ y --END GEEK CODE BLOCK-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all
On Thu, 2008-05-29 at 14:20 -0400, Robert Cummings wrote: > On Thu, 2008-05-29 at 13:07 -0500, Chris W wrote: > > What I want to do is find all links in an html file. I have the pattern > > below. It works as long as there is only one link on a line and as long > > as the whole link is one line. It seems there should be a way to get > > this to work with more than one link on a single line. The work around > > I have done for now is to read the whole file into a buffer and remove > > all new lines and then add a new line after every closing a tag. Then > > process each line. There has to be a better way. > > > > Any Ideas? Also note I don't want to find any a tags that don't have an > > href there probably aren't any but just in case. > > > > > > preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, > > PREG_PATTERN_ORDER); > > Your preg isn't going to return the URLs (even if it works), it's going > to return the labels of the links. But anyways... Actually it returned both, just not how I had thought first. I forgot to delete the above after I realized. My solution below works nonetheless :) > > $content = implode( '', @file( 'http://www.php.net' ) ); > > if( preg_match_all( > '#(]+href[^>]+>)(.*)#Umis', $content, $bits ) ) > { > print_r( $bits ); > } > > ?> > > Cheers, > Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all
On Thu, 2008-05-29 at 13:07 -0500, Chris W wrote: > What I want to do is find all links in an html file. I have the pattern > below. It works as long as there is only one link on a line and as long > as the whole link is one line. It seems there should be a way to get > this to work with more than one link on a single line. The work around > I have done for now is to read the whole file into a buffer and remove > all new lines and then add a new line after every closing a tag. Then > process each line. There has to be a better way. > > Any Ideas? Also note I don't want to find any a tags that don't have an > href there probably aren't any but just in case. > > > preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, > PREG_PATTERN_ORDER); Your preg isn't going to return the URLs (even if it works), it's going to return the labels of the links. But anyways... http://www.php.net' ) ); if( preg_match_all( '#(]+href[^>]+>)(.*)#Umis', $content, $bits ) ) { print_r( $bits ); } ?> Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all
What I want to do is find all links in an html file. I have the pattern below. It works as long as there is only one link on a line and as long as the whole link is one line. It seems there should be a way to get this to work with more than one link on a single line. The work around I have done for now is to read the whole file into a buffer and remove all new lines and then add a new line after every closing a tag. Then process each line. There has to be a better way. Any Ideas? Also note I don't want to find any a tags that don't have an href there probably aren't any but just in case. preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, PREG_PATTERN_ORDER); -- Chris W KE5GIX "Protect your digital freedom and privacy, eliminate DRM, learn more at http://www.defectivebydesign.org/what_is_drm"; Ham Radio Repeater Database.preg_match_all("/(< *a[^>]*href[^>]+>)(.*)<\/a>/", $Line, $matches, PREG_PATTERN_ORDER); http://hrrdb.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all Help
Assuming you know all the permissible div tag classes you want to capture the contents of I'd make an array list of them and the use a foreach() loop and capture the contents you want and not try to capture the contents between the channel divs. Assemble the output array inside the loop. You can also easily keep track of which channel ID the contents came from. What you are attempting directly with preg_match_all() is possible; but, the required pattern is very messy and will be hard to test to make certain it's perfect. [EMAIL PROTECTED] wrote: Okay use this as an example I want put parse the html document and toss everything between the two Div class channels into an array. The problem I am having is that I cannot grab everything in between the Pattern of the preg_match_all. If I preg_match_all('/]*>/i',$document,$elements); it works perfection But only arrays the single div statement not everything from div to div. I think somewhere the syntax of the preg_match_all or the implode that is not allow this function to work. Html document Station Manager Because you Can! Php script function pullchannel($document) { preg_match_all('/]*>(.*)]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; } -Original Message- From: Jim Lucas [mailto:[EMAIL PROTECTED] Sent: Thursday, October 11, 2007 9:41 PM To: [EMAIL PROTECTED] Cc: php-general@lists.php.net Subject: Re: [PHP] preg_match_all Help [EMAIL PROTECTED] wrote: I have tried this many way and for some reason I cannot pull content between the 2 pattern options. function pullchannel($document) { preg_match_all('/]*>(.*)]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; } Give us and example of the input data. And tell us from that example, what it is you are expecting to extract from it. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all Help
[EMAIL PROTECTED] wrote: ... It would help to see the input text and to know exactly what you're trying to match. -- Richard Heyes +44 (0)800 0213 172 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match_all Help
Okay use this as an example I want put parse the html document and toss everything between the two Div class channels into an array. The problem I am having is that I cannot grab everything in between the Pattern of the preg_match_all. If I preg_match_all('/]*>/i',$document,$elements); it works perfection But only arrays the single div statement not everything from div to div. I think somewhere the syntax of the preg_match_all or the implode that is not allow this function to work. Html document Station Manager Because you Can! Php script function pullchannel($document) { preg_match_all('/]*>(.*)]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; } -Original Message- From: Jim Lucas [mailto:[EMAIL PROTECTED] Sent: Thursday, October 11, 2007 9:41 PM To: [EMAIL PROTECTED] Cc: php-general@lists.php.net Subject: Re: [PHP] preg_match_all Help [EMAIL PROTECTED] wrote: > I have tried this many way and for some reason > > I cannot pull content between the 2 pattern options. > > > > > > function pullchannel($document) > > { > > preg_match_all('/]*>(.*) class="channel" [^<>]*>/i',$document,$elements); > > $match = implode("\r\n",$elements[0]); > > $match = str_replace('"',"","$match"); > > return $match; > > } > > > > > > Give us and example of the input data. And tell us from that example, what it is you are expecting to extract from it. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all Help
[EMAIL PROTECTED] wrote: I have tried this many way and for some reason I cannot pull content between the 2 pattern options. function pullchannel($document) { preg_match_all('/]*>(.*)]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; } Give us and example of the input data. And tell us from that example, what it is you are expecting to extract from it. Jim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all Help
I have tried this many way and for some reason I cannot pull content between the 2 pattern options. function pullchannel($document) { preg_match_all('/]*>(.*)]*>/i',$document,$elements); $match = implode("\r\n",$elements[0]); $match = str_replace('"',"","$match"); return $match; }
Re: [PHP] preg_match_all to match tags
Ive already finished the code and pasted it to this mailing list :) Just an fyi. Ólafur Waage > 2007/8/11, Tijnema <[EMAIL PROTECTED]>: > > On 8/11/07, Stut <[EMAIL PROTECTED]> wrote: > > > Tijnema wrote: > > > > On 8/11/07, Richard Heyes <[EMAIL PROTECTED]> wrote: > > > >> Richard Heyes wrote: > > > How can i match an image tag correctly so it does not cause any > > > issues > > > with how the user adds the image. > > > >>> preg_match_all('/]*>/Ui'); > > > >>> > > > >>> Off the top of my head. This wouldn't allow for using the right angle > > > >>> bracket in the img tag, but that's almost never going to happen in > > > >>> reailty. > > > >> Oops that should be: > > > >> > > > >> preg_match_all('/]*>/Ui', $input, $matches); > > > >> > > > >> -- > > > >> Richard Heyes > > > > > > > > < img src="image.jpg"> > > > > > > > > Your script doesn't catch above ;) > > > > > > That's not valid HTML and won't get displayed correctly in most browsers. > > > > > > -Stut > > > > hmm.. damn.. you're right :P I always assumed it was just correct... > > > > Tijnema > > -- > > Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
On 8/11/07, Stut <[EMAIL PROTECTED]> wrote: > Tijnema wrote: > > On 8/11/07, Richard Heyes <[EMAIL PROTECTED]> wrote: > >> Richard Heyes wrote: > How can i match an image tag correctly so it does not cause any issues > with how the user adds the image. > >>> preg_match_all('/]*>/Ui'); > >>> > >>> Off the top of my head. This wouldn't allow for using the right angle > >>> bracket in the img tag, but that's almost never going to happen in > >>> reailty. > >> Oops that should be: > >> > >> preg_match_all('/]*>/Ui', $input, $matches); > >> > >> -- > >> Richard Heyes > > > > < img src="image.jpg"> > > > > Your script doesn't catch above ;) > > That's not valid HTML and won't get displayed correctly in most browsers. > > -Stut hmm.. damn.. you're right :P I always assumed it was just correct... Tijnema -- Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
Tijnema wrote: On 8/11/07, Richard Heyes <[EMAIL PROTECTED]> wrote: Richard Heyes wrote: How can i match an image tag correctly so it does not cause any issues with how the user adds the image. preg_match_all('/]*>/Ui'); Off the top of my head. This wouldn't allow for using the right angle bracket in the img tag, but that's almost never going to happen in reailty. Oops that should be: preg_match_all('/]*>/Ui', $input, $matches); -- Richard Heyes < img src="image.jpg"> Your script doesn't catch above ;) That's not valid HTML and won't get displayed correctly in most browsers. -Stut -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
> < img src="image.jpg"> Your script doesn't catch above ;) So don't write HTML like that. Depends where the HTML is coming from, it might be user input Ok, add \s* after the initial angle bracket. -- Richard Heyes +44 (0)844 801 1072 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
On 8/11/07, Richard Heyes <[EMAIL PROTECTED]> wrote: > > < img src="image.jpg"> > > > > Your script doesn't catch above ;) > > So don't write HTML like that. > Depends where the HTML is coming from, it might be user input Tijnema -- Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
> < img src="image.jpg"> Your script doesn't catch above ;) So don't write HTML like that. -- Richard Heyes +44 (0)844 801 1072 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
On 8/11/07, Richard Heyes <[EMAIL PROTECTED]> wrote: > Richard Heyes wrote: > >> How can i match an image tag correctly so it does not cause any issues > >> with how the user adds the image. > > > > preg_match_all('/]*>/Ui'); > > > > Off the top of my head. This wouldn't allow for using the right angle > > bracket in the img tag, but that's almost never going to happen in reailty. > > Oops that should be: > > preg_match_all('/]*>/Ui', $input, $matches); > > -- > Richard Heyes < img src="image.jpg"> Your script doesn't catch above ;) Tijnema -- Vote for PHP Color Coding in Gmail! -> http://gpcc.tijnema.info -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
Richard Heyes wrote: How can i match an image tag correctly so it does not cause any issues with how the user adds the image. preg_match_all('/]*>/Ui'); Off the top of my head. This wouldn't allow for using the right angle bracket in the img tag, but that's almost never going to happen in reailty. Oops that should be: preg_match_all('/]*>/Ui', $input, $matches); -- Richard Heyes +44 (0)844 801 1072 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
How can i match an image tag correctly so it does not cause any issues with how the user adds the image. preg_match_all('/]*>/Ui'); Off the top of my head. This wouldn't allow for using the right angle bracket in the img tag, but that's almost never going to happen in reailty. -- Richard Heyes +44 (0)844 801 1072 http://www.websupportsolutions.co.uk Knowledge Base and HelpDesk software that can cut the cost of online support -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
At 11:45 PM + 8/9/07, Ólafur Waage wrote: I know this isn't exactly a php related question but due to the quality of answers ive seen lately ill give this a shot. (yes yes im smoothing up the crowd before the question) I have a weblog system that i am creating, the trouble is that if a user links to an external image larger than 500pixels in width, it messes with the whole layout. I had found some regex code im using atm but its not good at matching the entire image tag. It seems to ignore properties after the src declaration and not match tags that have properties before the src declaration . preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", $data, $matches); print_r($matches); This currently makes two arrays for me, the source location from all img tags and a large part of the tag itself. But not the entire tag. What i do is i match the img tag, find the src, get the image properties, and if the width is more than 500, i shrink it down and add width="X" and height="Y" properties to the image tag. How can i match an image tag correctly so it does not cause any issues with how the user adds the image. You could set a class attribute for the image in html and scale it in css. An img {width: 100%;} would hold the size to the maximum of the parent. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
On Thu, August 9, 2007 6:45 pm, Ólafur Waage wrote: > I know this isn't exactly a php related question but due to the > quality of answers ive seen lately ill give this a shot. (yes yes im > smoothing up the crowd before the question) > > I have a weblog system that i am creating, the trouble is that if a > user links to an external image larger than 500pixels in width, it > messes with the whole layout. > > I had found some regex code im using atm but its not good at matching > the entire image tag. It seems to ignore properties after the src > declaration and not match tags that have properties before the src > declaration . > > preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", > $data, $matches); > print_r($matches); > > This currently makes two arrays for me, the source location from all > img tags and a large part of the tag itself. But not the entire tag. > > What i do is i match the img tag, find the src, get the image > properties, and if the width is more than 500, i shrink it down and > add width="X" and height="Y" properties to the image tag. > > How can i match an image tag correctly so it does not cause any issues > with how the user adds the image. Scaling the image in the browser is horrible for performance on the client side... The entire image still gets downloaded, and then the poor browser has to scale this monster image down. You may want to re-think your plan of attack... You could, for example, force users to only use "registered" images, and if they "register" an image large than 500, use http://php.net/gd to scale it down. As far as matching the image tag correctly goes, I'd have to suggest that you try using a DOM to parse the HTML instead of regex. That said, to get the WHOLE img tag in the same vein as you are using now: preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*>)/i", Note the addition of a closing ">" which will mark the end of the img tag. The [img] and [src] are kind of wonky, really, as they would also match this bit of nonsense: Sometimes italics could have bogus attributes. YMMV -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some indie artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
Guys i would like to thank you for the help. Jan i used some of your code to help me get this. There was one issue with yours, preg_match_all while in a foreach will only match the last match and output that as the $m array. Here is the code, i hope someone else can use it. Its a working code in PHP4 and PHP5. I am currenly wrapping the imageManip(); around the $_POST variable that is the blog post when im posting it to the SQL. So the getimagesize(); only has to run once. There is one bug, if the user resizes the image manually to something less than 590, to say maybe 400, this program will still resize it to 590. function imageProportions($image) { $imageLoad = @getimagesize($image); // if the image is larger than 590 pixels, it will resize both height and width // if not it will do nothing to the variables. if($imageLoad[0] > 590) { $proportion = $imageLoad[0] / $imageLoad[1]; $imageLoad[0] = 590; $imageLoad[1] = $imageLoad[0] / $proportion; return array($imageLoad[0], ceil($imageLoad[1])); } else { return array($imageLoad[0], $imageLoad[1]); } } function imageManip($data) { // match all image tags (thanks to Jan Reiter) @preg_match_all("/\< *[img][^\>]*[.]*\>/i", $data, $matches); if( is_array($matches[0]) ) { // put all those image tags in one string, since preg match all needs the data // to be in a string format foreach($matches[0] as $match) { $imageMatch .= $match; } // match all source links within the original preg match all output @preg_match_all("/src=\"(.+?)\"/i", $imageMatch, $m); // for each match that has the same key as the second match, replace the entire // tag with my tag that includes width, height and border="0" foreach($matches[0] as $imageTagKey => $imageTag) { foreach($m[1] as $imageSrcKey => $imageSrc) { if($imageTagKey == $imageSrcKey) { $imageStats = imageProportions($imageSrc); $data = str_replace($imageTag, "", $data); } } } } return $data; } 2007/8/10, Jan Reiter <[EMAIL PROTECTED]>: > Maybe this is what you are searching for: > > $images = array(); > $data = "blah src=blah.png src=gg.tiff>"; > > preg_match_all("/\< *[img][^\>]*[.]*\>/i", $data, $matches); > foreach($matches[0] as $match) > { > preg_match_all("/(src|height|width)*= *[\"\']{0,1}([^\"\'\ \>]*)/i", > $match, $m); > $images[] = array_combine($m[1],$m[2]); > } > > print_r($image); > > It will produce: > > Array > ( > [0] => Array > ( > [src] => img.png > [width] => 400 > [height] => 600 > ) > > [1] => Array > ( > [src] => gg.tiff > ) > ) > > I wrote it just as an example. So you may modify it for your needs! > Does anyone know if there is a way to put this into ONE regex?? > > Jan > > -Original Message- > From: brian [mailto:[EMAIL PROTECTED] > Sent: Friday, August 10, 2007 3:18 AM > To: php-general@lists.php.net > Subject: Re: [PHP] preg_match_all to match tags > > Ólafur Waage wrote: > > I know this isn't exactly a php related question but due to the > > quality of answers ive seen lately ill give this a shot. (yes yes im > > smoothing up the crowd before the question) > > > > I have a weblog system that i am creating, the trouble is that if a > > user links to an external image larger than 500pixels in width, it > > messes with the whole layout. > > > > I had found some regex code im using atm but its not good at matching > > the entire image tag. It seems to ignore properties after the src > > declaration and not match tags that have properties before the src > > declaration . > > > > preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", > > $data, $matches); > > print_r($matches); > > > > This currently makes two arrays for me, the source location from all > > img tags and a large part of the tag itself. But not the entire tag. > > > > What i do is i match the img tag, find the src, get the image > > properties, and if the width is more than 500, i shrink it down and > > add width="X" and height="Y" properties to the image tag. > > > > How can i match an image tag correctly so it does not cause any issues > > with how the user adds the image. > > > > > #your_content_div img { max-width: 500px !important; } > > > OK, so it won't work with IE6. Scre
RE: [PHP] preg_match_all to match tags
Maybe this is what you are searching for: $images = array(); $data = "blah src=blah.png "; preg_match_all("/\< *[img][^\>]*[.]*\>/i", $data, $matches); foreach($matches[0] as $match) { preg_match_all("/(src|height|width)*= *[\"\']{0,1}([^\"\'\ \>]*)/i", $match, $m); $images[] = array_combine($m[1],$m[2]); } print_r($image); It will produce: Array ( [0] => Array ( [src] => img.png [width] => 400 [height] => 600 ) [1] => Array ( [src] => gg.tiff ) ) I wrote it just as an example. So you may modify it for your needs! Does anyone know if there is a way to put this into ONE regex?? Jan -Original Message- From: brian [mailto:[EMAIL PROTECTED] Sent: Friday, August 10, 2007 3:18 AM To: php-general@lists.php.net Subject: Re: [PHP] preg_match_all to match tags Ólafur Waage wrote: > I know this isn't exactly a php related question but due to the > quality of answers ive seen lately ill give this a shot. (yes yes im > smoothing up the crowd before the question) > > I have a weblog system that i am creating, the trouble is that if a > user links to an external image larger than 500pixels in width, it > messes with the whole layout. > > I had found some regex code im using atm but its not good at matching > the entire image tag. It seems to ignore properties after the src > declaration and not match tags that have properties before the src > declaration . > > preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", > $data, $matches); > print_r($matches); > > This currently makes two arrays for me, the source location from all > img tags and a large part of the tag itself. But not the entire tag. > > What i do is i match the img tag, find the src, get the image > properties, and if the width is more than 500, i shrink it down and > add width="X" and height="Y" properties to the image tag. > > How can i match an image tag correctly so it does not cause any issues > with how the user adds the image. > #your_content_div img { max-width: 500px !important; } OK, so it won't work with IE6. Screw them. But if the height is set in the img tag it'll keep that, so the image could become distorted. So, you could also do something like: #your_content_div img { visibility: none; } Then run some Javascript routine onload to properly figure the dimensions of each image. Adjust the width down to 500px, if necessary, then the height by whatever percent difference between original width over new width: var new_height = (original_width / 500) * original_height; Then, whether you change the dimensions of the image or not, change the visibility of each to 'visible'. So, um ... no PHP involved. brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all to match tags
Ólafur Waage wrote: I know this isn't exactly a php related question but due to the quality of answers ive seen lately ill give this a shot. (yes yes im smoothing up the crowd before the question) I have a weblog system that i am creating, the trouble is that if a user links to an external image larger than 500pixels in width, it messes with the whole layout. I had found some regex code im using atm but its not good at matching the entire image tag. It seems to ignore properties after the src declaration and not match tags that have properties before the src declaration . preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", $data, $matches); print_r($matches); This currently makes two arrays for me, the source location from all img tags and a large part of the tag itself. But not the entire tag. What i do is i match the img tag, find the src, get the image properties, and if the width is more than 500, i shrink it down and add width="X" and height="Y" properties to the image tag. How can i match an image tag correctly so it does not cause any issues with how the user adds the image. #your_content_div img { max-width: 500px !important; } OK, so it won't work with IE6. Screw them. But if the height is set in the img tag it'll keep that, so the image could become distorted. So, you could also do something like: #your_content_div img { visibility: none; } Then run some Javascript routine onload to properly figure the dimensions of each image. Adjust the width down to 500px, if necessary, then the height by whatever percent difference between original width over new width: var new_height = (original_width / 500) * original_height; Then, whether you change the dimensions of the image or not, change the visibility of each to 'visible'. So, um ... no PHP involved. brian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all to match tags
I know this isn't exactly a php related question but due to the quality of answers ive seen lately ill give this a shot. (yes yes im smoothing up the crowd before the question) I have a weblog system that i am creating, the trouble is that if a user links to an external image larger than 500pixels in width, it messes with the whole layout. I had found some regex code im using atm but its not good at matching the entire image tag. It seems to ignore properties after the src declaration and not match tags that have properties before the src declaration . preg_match_all("/\< *[img][^\>]*[src] *= *[\"\']{0,1}([^\"\'\ >]*)/i", $data, $matches); print_r($matches); This currently makes two arrays for me, the source location from all img tags and a large part of the tag itself. But not the entire tag. What i do is i match the img tag, find the src, get the image properties, and if the width is more than 500, i shrink it down and add width="X" and height="Y" properties to the image tag. How can i match an image tag correctly so it does not cause any issues with how the user adds the image. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all for dummies
Kristen G. Thorson wrote: I am a regex retard. good for you ;-) why not take the easy route and simply strip out all HTML comments (and whatever maybe inside them) from the string(s) before you do the search for the 'bbcode'? I am trying to pull keywords out of this crazy bbcode-like file, but only for bbcode-like code NOT enclosed in HTML comments. I currently have managed to create this regex: '/(?)/U' Which matches [!keyword::crazy bbcode!] and not That's a step in the right direction. But it includes in the match keywords within phrases like this: I want to ignore all bbcode within HTML quotes. How do I do this? thanks kgt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all for dummies
I am a regex retard. I am trying to pull keywords out of this crazy bbcode-like file, but only for bbcode-like code NOT enclosed in HTML comments. I currently have managed to create this regex: '/(?)/U' Which matches [!keyword::crazy bbcode!] and not That's a step in the right direction. But it includes in the match keywords within phrases like this: I want to ignore all bbcode within HTML quotes. How do I do this? thanks kgt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all question
Hello, I am using the following to do link replacing: preg_match_all("/<\s*a\s+[^>]*href\s*=\s*[\"']?([^\"' >]+)[\"' >]/isU",$file[$x],$matches); It works great for all but 'https' links. I am not that versed in regular expressions. Would anyone know what I need to put in there so that it will match on https links? Thanks, Chris
Re: Re: [PHP] preg_match_all problem
> From: "Ryan A" <[EMAIL PROTECTED]> > $content = str_replace($matches[$index][0],$value,$content); > > If you are interested in seeing the whole script, just scroll down. I'm not... but thanks. Did you read what I wrote? using preg_match twice and then str_replace is a waste. Learn to use preg_replace_callback() to make this worthwhile. ---John Holmes... UCCASS - PHP Survey System http://www.bigredspark.com/survey.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all problem
> From: "Ryan A" <[EMAIL PROTECTED]> > Below is my code for a templating kind of script, it basically searches for > 'tags' like this {movies 30} and replaces them, the problem is that if there > are 2 tags (eg: {movies 30}{movies 60}) it only replaces the first one...so > I tried using a preg_match_all... > > I tried using a preg_match_all at: > preg_match($pattern,$content,$matches[]); > but then $res is blank when $res usually contains the tag names... (using a > print_r($res); I just get Array ( [0] => Array ) ) > > **Start of code* > $categories=array("movies","action","cartoons","textlinks"); > > // This gets the tags and put it into matches[] > foreach ($categories as $value) > { > $pattern = "/{".$value." ([0-9_]+)?}/"; > preg_match($pattern,$content,$matches[]); > } > > foreach ($matches as $key =>$value){ > preg_match("/\w+/",$value[0],$res); > //print_r($res); > ***End of code* > > What am I doing wrong? I see where things are being matched, but how are they being replaced? What you really need here is preg_replace_callback(), probably. ---John Holmes... UCCASS - PHP Survey System http://www.bigredspark.com/survey.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all problem
Hi, Below is my code for a templating kind of script, it basically searches for 'tags' like this {movies 30} and replaces them, the problem is that if there are 2 tags (eg: {movies 30}{movies 60}) it only replaces the first one...so I tried using a preg_match_all... I tried using a preg_match_all at: preg_match($pattern,$content,$matches[]); but then $res is blank when $res usually contains the tag names... (using a print_r($res); I just get Array ( [0] => Array ) ) **Start of code* $categories=array("movies","action","cartoons","textlinks"); // This gets the tags and put it into matches[] foreach ($categories as $value) { $pattern = "/{".$value." ([0-9_]+)?}/"; preg_match($pattern,$content,$matches[]); } foreach ($matches as $key =>$value){ preg_match("/\w+/",$value[0],$res); //print_r($res); ***End of code* What am I doing wrong? Thanks, Ryan -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all but no preg_replace_all?
On Tue, 10 Aug 2004 18:51:43 +0200, Marten Lehmann <[EMAIL PROTECTED]> wrote: > Hello, > > I want to be sure, that preg_replace replaces all matches. But it > doesn't accept the /g modifier. And anyhow, there's no preg_replace_all > like there is an preg_match_all. Will preg_replace replace everything by > default? > Everytyhing in the original string that matches it will replace. > Regards > Marten > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- DB_DataObject_FormBuilder - The database at your fingertips http://pear.php.net/package/DB_DataObject_FormBuilder paperCrane --Justin Patrin-- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all but no preg_replace_all?
> I want to be sure, that preg_replace replaces all matches. But it > doesn't accept the /g modifier. And anyhow, there's no preg_replace_all > like there is an preg_match_all. Will preg_replace replace everything by > default? from php.net: mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit]) Searches subject for matches to pattern and replaces them with replacement. If limit is specified, then only limit matches will be replaced; if limit is omitted or is -1, then all matches are replaced. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all but no preg_replace_all?
Hello, I want to be sure, that preg_replace replaces all matches. But it doesn't accept the /g modifier. And anyhow, there's no preg_replace_all like there is an preg_match_all. Will preg_replace replace everything by default? Regards Marten -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preg_match_all problem
John W. Holmes wrote: damn... i left out the ending delimiter, too.. :) Chalk one up to Monday. ;) -- *** * _ __ __ __ _ * John Nichel * * | |/ /___ __ \ \/ /__ _ _| |__ ___ __ ___ _ __ * 716.856.9675 * * | ' http://www.KegWorks.com[EMAIL PROTECTED] * 14203 - 1321 * *** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preg_match_all problem
From: "John W. Holmes" <[EMAIL PROTECTED]> > From: "Jeff McKeon" <[EMAIL PROTECTED]> > > > Can anyone see why I'm getting this error message: > > > > "Warning: No ending delimiter '^' found in > > C:\Inetpub\wwwMIS_DEV\import_mvs.inc.php on line 126" > > > > From this line: > > > > if(preg_match_all("^([00])?.*$",$called,$found)) > > Because you do not have an ending delimiter. In fact, you don't have a > starting delimiter, either, but preg assumes you meant the ^ character to be > your delimiter. > > This is explained in all of the examples in the manual, but you must > surround your regular expression by a delimiter such as the / or # > character. This is because you can include modifiers after the delimiters to > further create your regex. > > if(preg_match_all("/^([00])?.*$",$called,$found)) damn... i left out the ending delimiter, too.. :) if(preg_match_all("/^([00])?.*$/",$called,$found)) ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preg_match_all problem
From: "Jeff McKeon" <[EMAIL PROTECTED]> > Can anyone see why I'm getting this error message: > > "Warning: No ending delimiter '^' found in > C:\Inetpub\wwwMIS_DEV\import_mvs.inc.php on line 126" > > From this line: > > if(preg_match_all("^([00])?.*$",$called,$found)) Because you do not have an ending delimiter. In fact, you don't have a starting delimiter, either, but preg assumes you meant the ^ character to be your delimiter. This is explained in all of the examples in the manual, but you must surround your regular expression by a delimiter such as the / or # character. This is because you can include modifiers after the delimiters to further create your regex. if(preg_match_all("/^([00])?.*$",$called,$found)) Although I doubt that'll work like you want it since [00] matches a zero, or another zero. It only matches one character. > I basically have a phone bill that sometimes has the phone number > preceeded by "00" and sometimes not. > > When it has the "00" I want to trim it with the substring command. I wouldn't even use preg for this. Just use ltrim() or if(substr($called,0,2)=='00')... ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Preg_match_all problem
Jeff McKeon wrote: Can anyone see why I'm getting this error message: "Warning: No ending delimiter '^' found in C:\Inetpub\wwwMIS_DEV\import_mvs.inc.php on line 126" From this line: if(preg_match_all("^([00])?.*$",$called,$found)) { substring($called,2,9); } I basically have a phone bill that sometimes has the phone number preceeded by "00" and sometimes not. When it has the "00" I want to trim it with the substring command. Thanks, Jeff You need to enclose your regex in /regex/ if ( preg_match_all ( "/^([00])?.*$/", $called, $found ) ) -- *** * _ __ __ __ _ * John Nichel * * | |/ /___ __ \ \/ /__ _ _| |__ ___ __ ___ _ __ * 716.856.9675 * * | ' http://www.KegWorks.com[EMAIL PROTECTED] * 14203 - 1321 * *** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Preg_match_all problem
Can anyone see why I'm getting this error message: "Warning: No ending delimiter '^' found in C:\Inetpub\wwwMIS_DEV\import_mvs.inc.php on line 126" >From this line: if(preg_match_all("^([00])?.*$",$called,$found)) { substring($called,2,9); } I basically have a phone bill that sometimes has the phone number preceeded by "00" and sometimes not. When it has the "00" I want to trim it with the substring command. Thanks, Jeff -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all : not all regular expressions ?
Hi, Saturday, January 24, 2004, 1:00:10 AM, you wrote: JJM> [newbie, please help] JJM> I'm trying to extract all URLs mentionning sound files from blocks of texts. JJM> I first tried with ereg and the following code works fine : JJM> $texte='TEST FIND\net voici un fichier son JJM> http://serveur/repertoire/fichier.gig ou JJM> ftp://serveur/repertoire/fichier.snd et JJM> ftp://serveur/repertoire/fichier.mp3 la suite JJM> http://serveur/repertoire/fichier.wav de mon texte'; JJM> if JJM> (ereg("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", JJM> $texte, $regs)) { JJM> echo $regs[0]."\n"; JJM> } JJM> else JJM> { JJM> echo "pas trouvé\n"; JJM> } JJM> the only problem is that it will only extract the first URL, so I did a JJM> small modification to use preg_match_all : JJM> if JJM> (preg_match_all("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", JJM> $texte, $matches)) { JJM> for ( $i=0 ; $i < count($matches[0]) ; $i++ ) { JJM> echo $matches[0][$i]."\n" ; JJM> } JJM> } else { JJM>echo "pas trouvé\n"; JJM> } JJM> but I have the following error message : *Warning*: Unknown modifier JJM> '+' in *e:\program files\easyphp1-7\www\test_ereg.php3* on line *4* JJM> where line 4 is the line with the regular expression after preg_match_all JJM> What's that ? preg_* functions needs delimiters for the expression like '//' or if there are likely to be / in the text you can use others like '!!' Its also a good idea to use single quotes so the expression gets ignored by php -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all : not all regular expressions ?
[newbie, please help] I'm trying to extract all URLs mentionning sound files from blocks of texts. I first tried with ereg and the following code works fine : $texte='TEST FIND\net voici un fichier son http://serveur/repertoire/fichier.gig ou ftp://serveur/repertoire/fichier.snd et ftp://serveur/repertoire/fichier.mp3 la suite http://serveur/repertoire/fichier.wav de mon texte'; if (ereg("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", $texte, $regs)) { echo $regs[0]."\n"; } else { echo "pas trouvé\n"; } the only problem is that it will only extract the first URL, so I did a small modification to use preg_match_all : if (preg_match_all("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]\.(mp3|snd|wav)", $texte, $matches)) { for ( $i=0 ; $i < count($matches[0]) ; $i++ ) { echo $matches[0][$i]."\n" ; } } else { echo "pas trouvé\n"; } but I have the following error message : *Warning*: Unknown modifier '+' in *e:\program files\easyphp1-7\www\test_ereg.php3* on line *4* where line 4 is the line with the regular expression after preg_match_all What's that ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all
* Thus wrote Floris ([EMAIL PROTECTED]): > hi, > I have this piece of code. but the problem is that he also links parts of > words (like: credits) and i wnat only standalone words (like: edit) > Does someone have i idea to correct this piece of code? > > Floris > > { > $regex1 = ">[^<]*("; > $regex2 = ")[^<]*<"; > preg_match_all("/".$regex1.$search_word.$regex2."/i", $string, $matches, Use the word boundry character: $regex1 = ">[^<]*\b("; $regex2 = ")\b[^<]*<"; Curt -- "I used to think I was indecisive, but now I'm not so sure." -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all
hi, I have this piece of code. but the problem is that he also links parts of words (like: credits) and i wnat only standalone words (like: edit) Does someone have i idea to correct this piece of code? Floris -- function link_search($search_words,$string,$id) { $word_no=0; foreach($search_words as $search_word) { $regex1 = ">[^<]*("; $regex2 = ")[^<]*<"; preg_match_all("/".$regex1.$search_word.$regex2."/i", $string, $matches, PREG_PATTERN_ORDER); foreach($matches[0] as $match) { preg_match("/$search_word/i", $match, $out); $case_sensitive_search_word = $out[0]; $chan = "$case_sensitive_search_word"; $newtext = str_replace($case_sensitive_search_word, $chan, $match); $string = str_replace($match, $newtext, $string); } $word_no++; } return $string; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all
How do I create a preg_match for something like this? 7 PM I want to store the individual times in an array and then loop through them if that makes sense... I tried this but when i try to echo the results back out it doesnt work preg_match_all("| (.*)\n \n|U",$read,$result); ?> Jay Fitzgerald, Design Director - CPW-A, CPWDS-A, CPWDV-A, CECM-A, CWCSB-A Bayou Internet - http://www.bayou.com Toll Free: 888.30.BAYOU (22968) Vox: 318.338.2034 / Fax: 318.338.2506 E-Mail: [EMAIL PROTECTED] ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match_all()
He needs both. /s makes dot to include new lines too, so you're right. Niklas -Original Message- From: Tom Rogers [mailto:[EMAIL PROTECTED] Sent: 3. huhtikuuta 2003 16:26 To: Thomas Johnsson Cc: [EMAIL PROTECTED] Subject: Re: [PHP] preg_match_all() Hi, Thursday, April 3, 2003, 11:33:02 PM, you wrote: TJ> I am having problems with preg_match_all spanning over newlines. TJ> Using /m does not seem to ignore the the newlines. TJ> // This works TJ> // Both contents inside and are found TJ> $html = ' TJ> One cell TJ> Another TJ> '; TJ> // This does not TJ> // Only the contents inside the first and are found TJ> // The only difference is that there is a linebreak efter the second TJ> $html = ' TJ> One cell TJ> TJ> Another TJ> '; TJ> preg_match_all("/(.*)<\/td>/m", $html, $out); TJ> I have been doing this before, but I can't remember how I got it working... TJ> Any thougts? I think you need /s to cope with newlines -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ### This message has been scanned by F-Secure Anti-Virus for Internet Mail. For more information, connect to http://www.F-Secure.com/ ### This message has been scanned by F-Secure Anti-Virus for Internet Mail. For more information, connect to http://www.F-Secure.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all()
Hi, Thursday, April 3, 2003, 11:33:02 PM, you wrote: TJ> I am having problems with preg_match_all spanning over newlines. TJ> Using /m does not seem to ignore the the newlines. TJ> // This works TJ> // Both contents inside and are found TJ> $html = ' TJ> One cell TJ> Another TJ> '; TJ> // This does not TJ> // Only the contents inside the first and are found TJ> // The only difference is that there is a linebreak efter the second TJ> $html = ' TJ> One cell TJ> TJ> Another TJ> '; TJ> preg_match_all("/(.*)<\/td>/m", $html, $out); TJ> I have been doing this before, but I can't remember how I got it working... TJ> Any thougts? I think you need /s to cope with newlines -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all()
I am having problems with preg_match_all spanning over newlines. Using /m does not seem to ignore the the newlines. // This works // Both contents inside and are found $html = ' One cell Another '; // This does not // Only the contents inside the first and are found // The only difference is that there is a linebreak efter the second $html = ' One cell Another '; preg_match_all("/(.*)<\/td>/m", $html, $out); I have been doing this before, but I can't remember how I got it working... Any thougts? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP preg_match_all()
It's in the manual: /U/ (PCRE_UNGREEDY) This modifier inverts the "greediness" of the quantifiers so that they are not greedy by default, but become greedy if followed by "?". It is not compatible with Perl. It can also be set by a (?U) modifier setting within the pattern. Jay Fitzgerald wrote: preg_match_all("||U", $read, $result2); can anyone fill me in if my logic is not correct and what exactly the |U is doing in this function? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] PHP preg_match_all()
I am having to edit a php script that one of our previous employees had written and I am having a problem understanding the preg_match_all function. preg_match_all("||U", $read, $result2); here is what I THINK I know: The | at the beginning signifies the start of the text to search for, then the actual text to search - the (.*) means to include everything after the / in the search as wellwhat I dont quite understand is what the |U is actually doingthen it tells the function what variable to $read and what new variable to store in: $result2 can anyone fill me in if my logic is not correct and what exactly the |U is doing in this function? Jay Fitzgerald, Design Director - CPW-A, CPWDS-A, CPWDV-A, CECM-A, CWCSB-A Bayou Internet - http://www.bayou.com Toll Free: 888.30.BAYOU (22968) Vox: 318.338.2034 / Fax: 318.338.2506 E-Mail: [EMAIL PROTECTED] ICQ: 38823829 / AIM: bayoujf / MSN: bayoujf / Yahoo: bayoujf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all()
On Mon, 3 Mar 2003 19:51:09 -0500, you wrote: >preg_match_all('/begincommand(.*)endcommand/',$messagebody,$commandOuttake,P >REG_PATTERN_ORDER); [...] > How >do I change the criteria to stop at the first instance of a match? How do I >parse out only up to the first instance of "endcommand"? Here's an excerpt from 'perldoc perlre': By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match. If you want it to match the minimum number of times possible, follow the quantifier with a "?". Note that the meanings don't change, just the "greediness". As John Holmes has already pointed out, you can add the U modifier, but I would recommend that you learn to use the ? quantifier, since this is more portable as Perl doesn't recognize the U modifier. So you'd want to change this: /begincommand(.*)endcommand/ to this: /begincommand(.*?)endcommand/ If you have an install of Perl handy I also recommend taking a look at 'perldoc perlretut', I've found it very helpful. HTH... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] preg_match_all()
Use a U modifier in your pattern. http://www.php.net/manual/en/pcre.pattern.modifiers.php ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ > -Original Message- > From: Vania Smrkovski [mailto:[EMAIL PROTECTED] > Sent: Monday, March 03, 2003 7:51 PM > To: [EMAIL PROTECTED] > Subject: [PHP] preg_match_all() > > As described in http://www.php.net/manual/en/function.preg-match-all.php, > I > have put in place a bit of code theoretically designed to parse out > snippets > of text embraced with an open and close tag. The code I am using is this: > > preg_match_all('/begincommand(.*)endcommand/',$messagebody,$commandOutta ke > ,P > REG_PATTERN_ORDER); > print $commandOuttake[0][0]." (0,0), ".$commandOuttake[0][1]." (0,1)\n"; > print $commandOuttake[1][0]." (1,0), ".$commandOuttake[1][1]." (1,1)\n"; > > For this input > > random words begincommand another test string 1[endcommand] a couple of > random words [begincommand]2nd instance of command in same email test > string > [endcommand] and then a bunch of nonsense > > this code produces this output: > > begincommand another test string 1[endcommand] a\r\ncouple of random words > [begincommand]2nd instance of command in same email\r\ntest string > [endcommand (0,0), (0,1) another test string 1[endcommand] a\r\ncouple of > random words [begincommand]2nd instance of command in same email\r\ntest > string [ (1,0), (1,1) > > > In other words, the fact that I have the begincommand ... endcommand > TWICE, > the preg_match_all only accepts the OUTER open and close tags. It never > stops at the first endcommand as I am trying to make it do. The string " > a\r\ncouple of random words" should never show up! > > I've tried this with and without the PREG_PATTERN_ORDER, with ereg, > preg_match and various and sundry other variations, and I am at a loss. > How > do I change the criteria to stop at the first instance of a match? How do > I > parse out only up to the first instance of "endcommand"? > > > I am not certain if I am subscribed directly to this list, so in > answering, > would you be so kind as to cc: [EMAIL PROTECTED] > > Thanks! > _ > Vania Smrkovski > Internet Design and Programming > [EMAIL PROTECTED] > http://pandorasdream.com/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all()
As described in http://www.php.net/manual/en/function.preg-match-all.php, I have put in place a bit of code theoretically designed to parse out snippets of text embraced with an open and close tag. The code I am using is this: preg_match_all('/begincommand(.*)endcommand/',$messagebody,$commandOuttake,P REG_PATTERN_ORDER); print $commandOuttake[0][0]." (0,0), ".$commandOuttake[0][1]." (0,1)\n"; print $commandOuttake[1][0]." (1,0), ".$commandOuttake[1][1]." (1,1)\n"; For this input random words begincommand another test string 1[endcommand] a couple of random words [begincommand]2nd instance of command in same email test string [endcommand] and then a bunch of nonsense this code produces this output: begincommand another test string 1[endcommand] a\r\ncouple of random words [begincommand]2nd instance of command in same email\r\ntest string [endcommand (0,0), (0,1) another test string 1[endcommand] a\r\ncouple of random words [begincommand]2nd instance of command in same email\r\ntest string [ (1,0), (1,1) In other words, the fact that I have the begincommand ... endcommand TWICE, the preg_match_all only accepts the OUTER open and close tags. It never stops at the first endcommand as I am trying to make it do. The string " a\r\ncouple of random words" should never show up! I've tried this with and without the PREG_PATTERN_ORDER, with ereg, preg_match and various and sundry other variations, and I am at a loss. How do I change the criteria to stop at the first instance of a match? How do I parse out only up to the first instance of "endcommand"? I am not certain if I am subscribed directly to this list, so in answering, would you be so kind as to cc: [EMAIL PROTECTED] Thanks! _ Vania Smrkovski Internet Design and Programming [EMAIL PROTECTED] http://pandorasdream.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all
hi, i try to parse html data with php's preg_match_all() function. here is a sample data that i try to parse: http://www.xxx.com"; class=M>xxx the regular expression that i use is: preg_match_all("/([^<]+)<\/a>/",$buffer,$ma tch); by this expression i get the same values more then one time. but i absolutely know that there's no repetation of same value. probably my problam is about the regular expression that i use. any help will be great help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all - how does it work?
On Monday 18 November 2002 01:09, Randall Perry wrote: > That was my understanding. Question is, why don't my print commands > work...or...how do you access 2 dimensional arrays in php? print_r() or var_dump() -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * /* If parents would only realize how they bore their children. -- G.B. Shaw */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all - how does it work?
That was my understanding. Question is, why don't my print commands work...or...how do you access 2 dimensional arrays in php? > Hi Randall, > > If you look closely at the definition of preg_match_all(), you'll see > that it generates an array of arrays--that's because, for each match, it > generates an array that corresponds to the result of a single call to > preg_match, then puts all the resulting array into another array. > > If you use PREG_SET_ORDER, your $match array contains an array for each > of the matches found. Each array then contains: > > * The entire matched string in element 0 > * Each of the substring (defined in brackets in your pattern) starting > from array 1. > > Hope this helps! > > > Marco > -- > > php|architect - The magazine for PHP Professionals > The first monthly worldwide magazine dedicated to PHP programmers > Check us out on the web at http://www.phparch.com > > > On Sun, 2002-11-17 at 11:13, Randall Perry wrote: >> I have some experience in using regular expressions in Perl, and have been >> able to use preg_match in php, but am having a problem with preg_match_all. >> >> I'm trying to extract data from an HTML table. Here's my preg_match call >> that correctly grabs the 1st row of data in the table. It grabs 4 columns of >> data: >> >> preg_match("|> class=\"CART_TD_REG\".+?(.*?)<.+?(.*?)<.+?(.*?)<.*?> ut.*?>[ ]*(.*?).*?|", $res, $match); >> >> If I use preg_match_all on the same table: >> preg_match_all("|> class=\"CART_TD_REG\".+?(.*?)<.+?(.*?)<.+?(.*?)<.*?> ut.*?>[ ]*(.*?).*?|", $res, $match, PREG_PATTERN_ORDER); >> >> ...and try to print output, I get: >> >> $match[0] = Array >> $match[0][0] = Array[0] >> $match[1][0] = Array[0] >> $match[0][1] = Array[0] >> $match[1][1] = Array[0] >> >> >> Same result with PREG_SETORDER. >> >> What am I doing wrong? >> >> -- >> Randall Perry >> sysTame >> >> Xserve Web Hosting/Co-location >> Website Development/Promotion >> Mac Consulting/Sales >> >> http://www.systame.com/ >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > -- Randall Perry sysTame Xserve Web Hosting/Co-location Website Development/Promotion Mac Consulting/Sales http://www.systame.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all - how does it work?
Hi Randall, If you look closely at the definition of preg_match_all(), you'll see that it generates an array of arrays--that's because, for each match, it generates an array that corresponds to the result of a single call to preg_match, then puts all the resulting array into another array. If you use PREG_SET_ORDER, your $match array contains an array for each of the matches found. Each array then contains: * The entire matched string in element 0 * Each of the substring (defined in brackets in your pattern) starting from array 1. Hope this helps! Marco -- php|architect - The magazine for PHP Professionals The first monthly worldwide magazine dedicated to PHP programmers Check us out on the web at http://www.phparch.com On Sun, 2002-11-17 at 11:13, Randall Perry wrote: > I have some experience in using regular expressions in Perl, and have been > able to use preg_match in php, but am having a problem with preg_match_all. > > I'm trying to extract data from an HTML table. Here's my preg_match call > that correctly grabs the 1st row of data in the table. It grabs 4 columns of > data: > > preg_match("| class=\"CART_TD_REG\".+?(.*?)<.+?(.*?)<.+?(.*?)<.*? ut.*?>[ ]*(.*?).*?|", $res, $match); > > If I use preg_match_all on the same table: > preg_match_all("| class=\"CART_TD_REG\".+?(.*?)<.+?(.*?)<.+?(.*?)<.*? ut.*?>[ ]*(.*?).*?|", $res, $match, PREG_PATTERN_ORDER); > > ...and try to print output, I get: > > $match[0] = Array > $match[0][0] = Array[0] > $match[1][0] = Array[0] > $match[0][1] = Array[0] > $match[1][1] = Array[0] > > > Same result with PREG_SETORDER. > > What am I doing wrong? > > -- > Randall Perry > sysTame > > Xserve Web Hosting/Co-location > Website Development/Promotion > Mac Consulting/Sales > > http://www.systame.com/ > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all - how does it work?
I have some experience in using regular expressions in Perl, and have been able to use preg_match in php, but am having a problem with preg_match_all. I'm trying to extract data from an HTML table. Here's my preg_match call that correctly grabs the 1st row of data in the table. It grabs 4 columns of data: preg_match("|(.*?)<.+?(.*?)<.+?(.*?)<.*?[ ]*(.*?).*?|", $res, $match); If I use preg_match_all on the same table: preg_match_all("|(.*?)<.+?(.*?)<.+?(.*?)<.*?[ ]*(.*?).*?|", $res, $match, PREG_PATTERN_ORDER); ...and try to print output, I get: $match[0] = Array $match[0][0] = Array[0] $match[1][0] = Array[0] $match[0][1] = Array[0] $match[1][1] = Array[0] Same result with PREG_SETORDER. What am I doing wrong? -- Randall Perry sysTame Xserve Web Hosting/Co-location Website Development/Promotion Mac Consulting/Sales http://www.systame.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all problem
> Hi, I'm a frog (french), > > I,ve some troubles with the preg_match_all function. > > > $strSearchWords = Trim($search); > $pattern = $strSearchWords; > > andwhile (!feof($openFile)) > { > $strFileContents .= fgets($openFile, 4096); > } > > $strPageTitle = htmlentities(GetFileMetaTag("", > "", $strFileContents)); > $strPageDescription = htmlentities(GetFileMetaTag(" name=\"description\" content=\"", "\">", $strFileContents)); > $strPageKeywords = htmlentities(GetFileMetaTag(" name=\"keywords\" content=\"", "\">", $strFileContents)); > $strFileContents = $strPageTitle." ".$strPageDescription." > ".$strPageKeywords; > $strFileContents = str_replace("; "," ",$strFileContents); > $strFileContents = str_replace(","," ",$strFileContents); > > then I get the following warning message: > > Delimiter must not be alphanumeric or backslash in : > if (preg_match_all($pattern,$strFileContents,$match) > 0) > > WHAT CAN I DO ??? > I had this problem only a day ago. You have forgotten to add slashes to your pattern. The variable $pattern looks something like this: "\d+\s" when it should look like this: "/\d+\s/" Hope that was helpful, Archie --- Archibald Zimonyi [EMAIL PROTECTED] "There is no logic like no logic" -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all problem
Hi, I'm a frog (french), I,ve some troubles with the preg_match_all function. $strSearchWords = Trim($search); $pattern = $strSearchWords; andwhile (!feof($openFile)) { $strFileContents .= fgets($openFile, 4096); } $strPageTitle = htmlentities(GetFileMetaTag("", "", $strFileContents)); $strPageDescription = htmlentities(GetFileMetaTag("", $strFileContents)); $strPageKeywords = htmlentities(GetFileMetaTag("", $strFileContents)); $strFileContents = $strPageTitle." ".$strPageDescription." ".$strPageKeywords; $strFileContents = str_replace("; "," ",$strFileContents); $strFileContents = str_replace(","," ",$strFileContents); then I get the following warning message: Delimiter must not be alphanumeric or backslash in : if (preg_match_all($pattern,$strFileContents,$match) > 0) WHAT CAN I DO ??? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] preg_match_all href|src function
Hi All, I have being working on PHP perl compaitable regular expressions for the last month and cannot work out how to program a preg_match_all that will get the "file.html" from the following examples: The preg_match_all I have below only works for but not for the other variations... preg_match_all("|href=\"?([^\"' >]+)|i", $data, $links); I tried the preg_match_all below, but that didn't work... preg_match_all("|(href|src)=([^\"']+)?([^\"' >]+)|i", $data, $links); Any help would be greatly appreciated. Regards, Michael. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] preg_match_all...grrrr!!!
On Tuesday 23 October 2001 02:47, PHPGalaxy.com wrote: > My matching pattern looks like this: > $engreg = > '/psPhoneEntry.py?firstname=(.*?)&lastname=(.*?)&street=(.*?)&city=(.*? >)&state=(.*?)&zip=(.*?)&phone=(.*?)\">/i'; > > Note the "/" at the beginning, and "/i" at the end. those have always > been there in other projects, and have worked. Is there anything else > I'm doing wrong here? I dont get any errors, but it returns 0 matches. > =) The php manual contains a good documentation of preg syntax. read that.. -- Christian Reiniger LGDC Webmaster (http://lgdc.sunsite.dk/) Results 1 - 10 of about 201,000,000. Search took 0.08 seconds - http://www.google.com/search?q=e -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] preg_match_all...grrrr!!!
"PHPGalaxy.com" wrote: > > ... > > A link from one such entry looks like this: > >psPhoneEntry.py?firstname=Adam&lastname=Collier&street=3912+Foley+Glen+Cir&city=Fenton&state=MI&zip=48430-3435&phone=8107507456 > > My matching pattern looks like this: > $engreg = > >'/psPhoneEntry.py?firstname=(.*?)&lastname=(.*?)&street=(.*?)&city=(.*?)&state=(.*?)&zip=(.*?)&phone=(.*?)\">/i'; > Try this pattern: $engreg = '/psPhoneEntry\.py\?firstname=(.*)&lastname=(.*)&street=(.*)&city=(.*)&state=(.*)&zip=(.*)&phone=(.*)/i'; -- Pavel a.k.a. Papi -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] preg_match_all...grrrr!!!
I've never had good luck with this function. I first learned how to (sorta) use it from looking at other code. It worked fine when I made a meta search engine, but when I tried on expanding on it, well, I've started losing hair. =) Here's the scenario: I'm trying to parse results from Yahoo's People Search page, to "grab" the info from it. A specific link in the results contains all the info I need for each entry. A link from one such entry looks like this: psPhoneEntry.py?firstname=Adam&lastname=Collier&street=3912+Foley+Glen+Cir&city=Fenton&state=MI&zip=48430-3435&phone=8107507456 My matching pattern looks like this: $engreg = '/psPhoneEntry.py?firstname=(.*?)&lastname=(.*?)&street=(.*?)&city=(.*?)&state=(.*?)&zip=(.*?)&phone=(.*?)\">/i'; Note the "/" at the beginning, and "/i" at the end. those have always been there in other projects, and have worked. Is there anything else I'm doing wrong here? I dont get any errors, but it returns 0 matches. =) ~ Tim -- - Tim PHP Galaxy: http://www.phpgalaxy.com/ The LavaWarp Engine: http://www.phpgalaxy.com/engine.php3 BitSearch: http://www.phpgalaxy.com/bitsearch.php3 MetaWarp: http://www.phpgalaxy.com/metawarp.php3 PhotoRate: http://www.phpgalaxy.com/photorate.php3 Earn $10 per order selling these scripts on your site! http://www.phpgalaxy.com/aff/