What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » [PHP] Help with regular expressions

[PHP] Help with regular expressions
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. [PHP] Help with regular expressions
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
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-24-2006 02:39 PM
Profile E-Mail PM Web Find Quote Report
-dt-
Scripting Contest Winner
*****

Avatar
;o

Posts: 1819
Reputation: 74
36 / Male / Flag
Joined: Mar 2004
RE: [PHP] Help with regular expressions
something like would do normal numbers , Im not sure how to do hex :P

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


This post was edited on 06-24-2006 at 02:45 PM by -dt-.
[Image: dt2.0v2.png]      Happy Birthday, WDZ
06-24-2006 02:45 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [PHP] Help with regular expressions
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?

This post was edited on 06-24-2006 at 03:11 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-24-2006 03:07 PM
Profile E-Mail PM Web Find Quote Report
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
RE: [PHP] Help with regular expressions
Declare $smileys_from  as global..

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

This post was edited on 06-24-2006 at 03:10 PM by surfichris.
06-24-2006 03:10 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
O.P. RE: [PHP] Help with regular expressions
$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

This post was edited on 06-24-2006 at 03:32 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-24-2006 03:12 PM
Profile E-Mail PM Web Find Quote Report
hmaster
Senior Member
****

Avatar

Posts: 716
Reputation: 24
33 / Male / Flag
Joined: Nov 2004
RE: [PHP] Help with regular expressions
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);
}


This post was edited on 06-24-2006 at 03:35 PM by hmaster.
[Image: sig.png]
06-24-2006 03:34 PM
Profile PM Web Find Quote Report
surfichris
Former Admin
*****

Avatar

Posts: 2365
Reputation: 81
Joined: Mar 2002
RE: [PHP] Help with regular expressions
You can pass an array directly to str_replace, hmaster. ;)
06-24-2006 03:38 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On