Re: Re: Filtering URLs problem..
| From: | Al | Date: | Fri, 23 Dec 2005 18:49:35 +0000 |
| Subject: | Re: Re: Filtering URLs problem.. | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-227853@lists.php.net to get a copy of this message | ||
Jochem Maas wrote:
...think there are a couple of single quotes missing in tyhe line above, ['\"] says either single or double quote. and the parentheses are probably meant to be square brackets: $types= '[http|ftp|https|mms|irc]'; Says: every "h" every "t" every "p" every "|"..... etc. He needs (http|ftp|https|mms|irc); Which says "http" or "ftp" or https .... etc. Note, I'm using $match[2], not $match[1].you don't mind if I forward that to my girlfriend? ;-) (the bit about me being correct)Jochem's correct. I was in too big a hurry trying to help. It wasobvious that Anders was not getting much useful help. His points 3 and 4the lack of help is due to the fact that the problem is much easier to explain/understand than to solve properly, and starting out with regular expressions is a steep learning curve. that said I think the OP has plenty of stuff to put his teeth into.are valid and I was not addressing them because they require more work than I have time to devote.fair enough :-)Here is corrected code. It works with the "Regex Coach". I did not try it with a php script. $types= (http|ftp|https|mms|irc);I think there are a couple of single quotes missing in tyhe line above, and the parentheses are probably meant to be square brackets: $types= '[http|ftp|https|mms|irc]';$pattern= "%<a\040href\040*=['\"]$types://((www.)*[\w/\.]+)['\"]>.+</a>%i"; // the "i" makes it non case sensitive if(preg_match($pattern, $URL_str, $match)){$URL= match[2];} else{User did not enter a complete link; do the simple thing} ..