Author Topic: [PHP] URL Regular Expression  (Read 15806 times)

0 Members and 1 Guest are viewing this topic.

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #15 on: September 13, 2005, 11:04:19 pm »
Inefficient.

Code: [Select]

$message = preg_replace("<REGULAR EXPRESSION THAT WORKS>", '<a href="\1">\1</a>', $message);


SO PWNS that.  I just need a working regular expression.  I'm shocked none of you have worked with them.  O_o

Well, not so much you, Joe.  You're a VB person =p

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [PHP] URL Regular Expression
« Reply #16 on: September 13, 2005, 11:56:54 pm »
<?
  
echo findurl("ftp://www.test.org str1 http://www.test.com str2 ftp://www.x86labs.org str3");

  function 
findurl($data) {
    
$ret "";
    
$words explode(" "$data);
    foreach(
$words as $word) {
      if (
substr($word07) == "http://") {
        
$ret $ret '<a href="' $word '">' $word "</a> ";
      }elseif (
substr($word06) == "ftp://") {
        
$ret $ret '<a href="' $word '">' $word "</a> ";
      }else{
        
$ret $ret $word " ";
      }
    }
    return 
$ret;
  }
?>


*backs away while it still works*

http://www.javaop.com/~joe/url.php
« Last Edit: September 15, 2005, 08:03:42 pm by Joe[e2] »
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #17 on: September 14, 2005, 12:04:40 am »
Thanks, but I'm going to stick to finding a working regular expression.  :P

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [PHP] URL Regular Expression
« Reply #18 on: September 14, 2005, 12:23:30 am »
A WORKING? WTF U SMOKIN NGR?
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Mythix

  • The Dude
  • x86
  • Hero Member
  • *****
  • Posts: 1569
  • Victory
    • View Profile
    • Dark-Wire
Re: [PHP] URL Regular Expression
« Reply #19 on: September 14, 2005, 02:45:52 pm »
pft we all know joe hardcoded those links.
Philosophy, n. A route of many roads leading from nowhere to nothing.

- Ambrose Bierce


Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #20 on: September 14, 2005, 04:32:26 pm »
Code: [Select]
<?php

$seach = array();
$replace = array();

$search[] = 

"^(((ht|f)tp(s?))\:\/\/)(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.([a-z])(\:[0-9]+)*((\/?))(([a-zA-Z0-9\.

\,\;\?\'\\\=\/\_\-\#]+)?)^"
;
$replace[] = '<a href="\0" target="_blank">\0</a>';

$string "Hello.  This is a test string.  http://www.google.com  <br /><br />I hope this 

serves as proof that regular expressions > all.  http://sidoh.no-ip.org/reg-ex.php FTW. <br /><br 

/> Visit http://www.x86labs.org/forum/index.php?topic=2790.msg27101#msg27101 for more 

information!"
;

$string preg_replace($search$replace$string);

echo $string;

?>

http://sidoh.no-ip.org/reg-ex.php

Owned.
« Last Edit: September 14, 2005, 04:35:31 pm by Sidoh »

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [PHP] URL Regular Expression
« Reply #21 on: September 14, 2005, 05:07:38 pm »
You should be shot? =p
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #22 on: September 15, 2005, 12:55:27 pm »

Offline deadly7

  • 42
  • Moderator
  • Hero Member
  • *****
  • Posts: 6496
    • View Profile
Re: [PHP] URL Regular Expression
« Reply #23 on: September 15, 2005, 06:11:58 pm »
Sidoh, do you always mess up your code?
Code: [Select]
<?php

[
b]$seach = array();[/b]
$replace = array();

[b]$search[] = [/b]

"^(((ht|f)tp(s?))\:\/\/)(www.|[a-zA-Z].)[a-zA-Z0-9\-\.]+\.([a-z])(\:[0-9]+)*((\/?))(([a-zA-Z0-9\.

\,\;\?\'\\\=\/\_\-\#]+)?)^"
;
$replace[] = '<a href="\0" target="_blank">\0</a>';

$string "Hello. This is a test string. http://www.google.com <br /><br />I hope this 

serves as proof that regular expressions > all. http://sidoh.no-ip.org/reg-ex.php FTW. <br /><br 

/> Visit http://www.x86labs.org/forum/index.php?topic=2790.msg27101#msg27101 for more 

information!"
;

$string preg_replace($search$replace$string);

echo $string;

?>

http://sidoh.no-ip.org/reg-ex.php

Owned.
[17:42:21.609] <Ergot> Kutsuju you're girlfrieds pussy must be a 403 error for you
 [17:42:25.585] <Ergot> FORBIDDEN

on IRC playing T&T++
<iago> He is unarmed
<Hitmen> he has no arms?!

on AIM with a drunk mythix:
(00:50:05) Mythix: Deadly
(00:50:11) Mythix: I'm going to fuck that red dot out of your head.
(00:50:15) Mythix: with my nine

Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #24 on: September 15, 2005, 06:16:32 pm »
Know that [ php] is a syntax highlighted tag, so don't expect the bold tag will work in the future.

Additionally, since PHP contains the ability to define variables implicitly, I didn't mess up my code.  It works fine, there's just memory allocated for an array that isn't used.  :P
« Last Edit: September 15, 2005, 06:18:33 pm by Sidoh »

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [PHP] URL Regular Expression
« Reply #25 on: September 15, 2005, 08:03:05 pm »
echo(findurl(""HelloThis is a test stringhttp://www.google.com <br /><br />I hope this serves as proof that regular expressions > all. http://sidoh.no-ip.org/reg-ex.php FTW. <br /><br /> Visit http://www.x86labs.org/forum/index.php?topic=2790.msg27101#msg27101 for more information!");
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #26 on: September 15, 2005, 08:17:50 pm »
echo(findurl(""HelloThis is a test stringhttp://www.google.com <br /><br />I hope this serves as proof that regular expressions > all. http://sidoh.no-ip.org/reg-ex.php FTW. <br /><br /> Visit http://www.x86labs.org/forum/index.php?topic=2790.msg27101#msg27101 for more information!");

o_O

Offline Joe

  • B&
  • x86
  • Hero Member
  • *****
  • Posts: 10319
  • In Soviet Russia, text read you!
    • View Profile
    • Github
Re: [PHP] URL Regular Expression
« Reply #27 on: September 15, 2005, 08:58:53 pm »
You can fix it.
I'd personally do as Joe suggests

You might be right about that, Joe.


Offline Sidoh

  • Moderator
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: [PHP] URL Regular Expression
« Reply #28 on: September 15, 2005, 09:02:22 pm »

Offline Blaze

  • x86
  • Hero Member
  • *****
  • Posts: 7136
  • Canadian
    • View Profile
    • Maide
Re: [PHP] URL Regular Expression
« Reply #29 on: September 15, 2005, 09:13:06 pm »

<?php

echo(findurl("Hello. This is a test string. http://www.google.com <br /><br />I hope this serves as proof that regular expressions > all. http://sidoh.no-ip.org/reg-ex.php FTW. <br /><br /> Visit http://www.x86labs.org/forum/index.php?topic=2790.msg27101#msg27101 for more information!"));

?>


Like that?
And like a fool I believed myself, and thought I was somebody else...