Re: [PHP] Extract url from string

2007-03-12 Thread Tijnema !

On 3/12/07, Brad Fuller [EMAIL PROTECTED] wrote:


Hey guys,

I've been banging my head against the wall trying to figure out the right
pattern to use to extract a URL from a string using preg_match().

I've been STFW for a while now, and all the examples that I find are for
extracting URLs from within a a href= tag.

Here's what I need, and I'm sure it's quite common, especially with forums
etc.; hopefully someone has a code snippet they can share.

INPUT:

This is some text http://www.example.com/page.html this is some more text.

OUTPUT:

This is some text a
href=http://www.example.com/page.html;http://www.example.com/page.html
/a
this is some more text.

Thx in advance,

-B



I'm not very familiar with PCRE, but you should search for a pattern
starting with http: and ends with a space.

Tijnema

--

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Extract url from string

2007-03-12 Thread Brad Fuller
 -Original Message-
 From: Tijnema ! [mailto:[EMAIL PROTECTED]
 Sent: Monday, March 12, 2007 1:10 PM
 To: Brad Fuller
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Extract url from string
 
 On 3/12/07, Brad Fuller [EMAIL PROTECTED] wrote:
 
  Hey guys,
 
  I've been banging my head against the wall trying to figure out the
 right
  pattern to use to extract a URL from a string using preg_match().
 
  I've been STFW for a while now, and all the examples that I find are for
  extracting URLs from within a a href= tag.
 
  Here's what I need, and I'm sure it's quite common, especially with
 forums
  etc.; hopefully someone has a code snippet they can share.
 
  INPUT:
 
  This is some text http://www.example.com/page.html this is some more
 text.
 
  OUTPUT:
 
  This is some text a
  href=http://www.example.com/page.html;http://www.example.com/page.html
  /a
  this is some more text.
 
  Thx in advance,
 
  -B
 
 
 I'm not very familiar with PCRE, but you should search for a pattern
 starting with http: and ends with a space.
 
 Tijnema
 
 --

I tried this:

preg_match(/http(s)?:\/\/(*.?)\s/, $stringUrl, $matches)

But my pattern syntax is messed up cuz I get this error:

Warning: preg_match() [function.preg-match]: Compilation failed:
nothing to repeat at offset 15 in /path/to/myfile.php on line 5

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Extract url from string

2007-03-12 Thread Richard Lynch
The problem is that URL has a very specific meaning, and includes a
BUNCH of complexities you may or may not need...

Download The Regex Coach and play around with some sample inputs
until you find what works for your needs, which is not a full-blown
URL detector, since that would be very complicated indeed.

On Mon, March 12, 2007 12:06 pm, Brad Fuller wrote:
 Hey guys,

 I've been banging my head against the wall trying to figure out the
 right
 pattern to use to extract a URL from a string using preg_match().

 I've been STFW for a while now, and all the examples that I find are
 for
 extracting URLs from within a a href= tag.

 Here's what I need, and I'm sure it's quite common, especially with
 forums
 etc.; hopefully someone has a code snippet they can share.

 INPUT:

 This is some text http://www.example.com/page.html this is some more
 text.

 OUTPUT:

 This is some text a
 href=http://www.example.com/page.html;http://www.example.com/page.html/a
 this is some more text.

 Thx in advance,

 -B

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving 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