Current location: Hot Scripts Forums » Programming Languages » PHP » Regular Expression IP Address Replacement

Regular Expression IP Address Replacement

Reply
  #1 (permalink)  
Old 11-19-04, 05:07 PM
CMIVXX's Avatar
CMIVXX CMIVXX is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Regular Expression IP Address Replacement

OK, I have this wonderful regular expression that replaces IP addresses in a variable. The catch is that I want to replace the IP address with the same IP address, just with a link around it that you can click on for further information.

On the example below, I need to replace the $ip with the actual IP address from the expression.

$msg = ereg_replace("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})", "<a href=\"script.php?$ip\">$ip</a>", $msg);

Can anyone help me?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-20-04, 04:56 AM
perleo perleo is offline
Coding Addict
 
Join Date: Jul 2003
Location: Ireland
Posts: 269
Thanks: 0
Thanked 0 Times in 0 Posts
what exactly you trying to do?

the IP is transfered from script to script over the URL ?

then you want to replace the link on the page with the IP like page.php?ip=iphere

that would be

$ip = $_GET['ip'];

and then in every link just put the ?ip=$ip after the pagename
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-20-04, 07:24 AM
Acecool's Avatar
Acecool Acecool is offline
Aspiring Coder
 
Join Date: Nov 2003
Posts: 506
Thanks: 0
Thanked 0 Times in 0 Posts
For each search, you can use \\#

so \\1 should show a part of it.
__________________
Check Acecoolco.com for PHP Tutorials, and other tuts
If you plan on contacting me, please read this: Legal Terms & Conditions
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-20-04, 07:27 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
something like this?
PHP Code:
$ip '82.181.38.134';
$msg preg_replace("#((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9]))#sie""stripslashes('\<a href=\"page.php?\\1\"\>\\1\</a\>')"$ip);
echo 
$msg
and btw.. the part matching the ip MUST be one long line..
and also i would like to point out that your code also accepts 999.999.999.999 witch is a invalid ip.
hope it helps
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I want a crowler and abstraction from Regular Expression oiranoinu Script Requests 4 11-25-04 11:31 PM
1 ip address only aemobile PHP 2 11-16-04 05:24 PM
Regular Expression Problem birdy Visual Basic 0 10-04-04 02:09 PM
Confused about the from address with php form processor AshleyQuick PHP 0 06-01-04 11:52 AM
suggest a regular expression gmadhukarreddy Perl 2 01-08-04 12:56 AM


All times are GMT -5. The time now is 03:48 AM.
vBulletin® Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.