It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum Script-archive

How to avoid RegEx

Share your completed scripts.

Moderator: Malcolm

How to avoid RegEx

Postby HotNoob on Wed Sep 22, 2010 3:21 am

I thought that i'd post this up.
While looking back at some of my scripts, i found this interesting way around for people who are preg_replace/regular expression retarded like most of us :D

Code: Select all
<?php

$meebo = $_POST['meeboRoom'];
$patterns = array(
                '<div style=\"width:',
                'px\"><style>.mcrmeebo { display: block; background:url(\"http://widget.meebo.com/r.gif\") no-repeat top right; } .mcrmeebo:hover { background:url(\"http://widget.meebo.com/ro.gif\") no-repeat top right; } </style><object width=\"',
                '\" height=\"',
                '\" ><param name=\"movie\" value=\"http://widget.meebo.com/mcr.swf?id=',
                '\"/><embed src=\"http://widget.meebo.com/mcr.swf?id=',
                '\" type=\"application/x-shockwave-flash\" width=\"',
                '\" height=\"',
                '\" /></object><a href=\"http://www.meebo.com/rooms\" class=\"mcrmeebo\"><img alt=\"http://www.meebo.com/rooms\" src=\"http://widget.meebo.com/b.gif\" width=\"',
                '\"height=\"45\" style=\"border:0px\"/></a></div>',
                '\" style=\"border:0px\"/></a></div>');
$meebo = str_replace($patterns, " ", $meebo);
$array = explode(" ", $meebo);

$meebo_id = $array[5];

?>


As you can see, by combining the explode function, you can put all of your unassigned variables in an array and then call them almost like you were using preg_replace/match.

:D

In fact, your results are essentially the same, with 10 times less of a head ache.

Of course tho, it does have its limitations :(
ps, i have never tested the efficiency of this script, so don't ask :(
HotNoob
100+ Club
 
Posts: 169
Joined: Sun May 02, 2010 1:38 am

Who is online

Users browsing this forum: No registered users and 0 guests