Shoutbox

[PHP] Help with regular expressions - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [PHP] Help with regular expressions (/showthread.php?tid=60964)

[PHP] Help with regular expressions by Matti on 06-24-2006 at 02:39 PM

Hi all!

I want to strip all occurancies of "·$" followed by a number or hexadecimal number out of a string... how can I do this using preg_replace()?
I don't have much experience with regular expressions, but I hope the Plus! community does. (A)

TIA! :D


RE: [PHP] Help with regular expressions by -dt- on 06-24-2006 at 02:45 PM

something like would do normal numbers , Im not sure how to do hex :P

code:
/·\$[0-9]{1,2}/


RE: [PHP] Help with regular expressions by Matti on 06-24-2006 at 03:07 PM

Thanks -dt-, but I have some other problems I think... :P

code:
$smileys_from = array("<:o)", ":)", ":-)", ":D", ":d", ":>", ";)", ";-)", ":o", ":O", ":-O", ":P", ":p", ":-p", ":-P", "(h)", "(H)", ":@", ":-@", ":$", ":-$", ":s", ":S", ":-S", ":-s", ":-(", ":(", ":<", ":'(", ":|", ":-|", "(6)", "(A)", "(a)", "(L)", "(l)", "(U)", "(u)", "(m)", "(M)", "(@)", "(&)", "(S)", "(*)", "(~)", "(8)", "(E)", "(e)", "(F)", "(f)", "(w)", "(W)", "(O)", "(o)", "(K)", "(k)", "(G)", "(g)", "(^)", "(p)", "(P)", "(i)", "(I)", "(C)", "(c)", "(t)", "(T)", "({)", "(})", "(B)", "(b)", "(D)", "(d)", "(Z)", "(z)", "(x)", "(X)", "(y)", "(Y)", "(n)", "(N)", ":[", ":-[", "(?)", "(%)", "(#)", "(R)", "(r)", ":-#", "8o|", "8-|", "^o)", ":-*", "+o(", "(sn)", "(tu)", "(pl)", "(||)", "(pi)", "(so)", "(au)", "(ap)", "(um)", "(ip)", "(co)", "(mp)", "(brb)", "(st)", "(yn)", "(h5)", "(mo)", "(bah)", ":^)", "*-)", "(li)", "8-)", "(ci)", "(xx)", "(nah)", "|-)");

function stripplus($string) {
    $search = array("[b]","[/b]","[u]","[/u]","[s]","[/s]","·#","·@","·'","·0");
    $string = str_replace($search, "", $string);
    foreach($smileys_from as $value) {
        $cur = "·!" . $value;
        $string = str_replace($cur, "", $string);
    }
    $string = preg_replace("/\[c=(\d{1,2})\]/", "", $string);
    $string = preg_replace("/\[\/c.*?\]/", "",$string);
    $string = preg_replace("/·\$[0-9]{1,2}/", "", $string);
    return $string;
}

$psm = stripplus("Test ·$4one·0 ·$2two·0 ·$8three·0... ·#bold·# ·@underlined·@ ·!:P ·!:)");

This is my function, and my smiley array. This function, however, only succeeds to execute the first 2 lines. All the other lines fail... :(

Any idea?
RE: [PHP] Help with regular expressions by surfichris on 06-24-2006 at 03:10 PM

Declare $smileys_from  as global..

function stripplus($string) {
global $simileys_from;
.....
}


RE: [PHP] Help with regular expressions by Matti on 06-24-2006 at 03:12 PM

$smileys_from isn't declared in the function itself... I don't think that caused the problem. :-/
Oh wait - it did! :D

Now how do I remove the color tags? :P

G2G... tell me tomorrow, so I can test it with MP!L. :D


RE: [PHP] Help with regular expressions by hmaster on 06-24-2006 at 03:34 PM

You have to seperate them one at a time I think.

code:
$search = array("[b]","[/b]","[u]","[/u]","[s]","[/s]","·#","·@","·'","·0");

for($i = 0; $i < count($search); $i++) {
$string = str_replace($search[$i], "", $string);
}


RE: [PHP] Help with regular expressions by surfichris on 06-24-2006 at 03:38 PM

You can pass an array directly to str_replace, hmaster. ;)