[PHP] Help with regular expressions |
Author: |
Message: |
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
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.
TIA!
|
|
06-24-2006 02:39 PM |
|
|
-dt-
Scripting Contest Winner
;o
Posts: 1819 Reputation: 74
36 / /
Joined: Mar 2004
|
RE: [PHP] Help with regular expressions
something like would do normal numbers , Im not sure how to do hex
code: /·\$[0-9]{1,2}/
This post was edited on 06-24-2006 at 02:45 PM by -dt-.
Happy Birthday, WDZ
|
|
06-24-2006 02:45 PM |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
Joined: Apr 2004
|
O.P. RE: [PHP] Help with regular expressions
Thanks -dt-, but I have some other problems I think...
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.
|
|
06-24-2006 03:07 PM |
|
|
surfichris
Former Admin
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 |
|
|
Matti
Elite Member
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / /
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!
Now how do I remove the color tags?
G2G... tell me tomorrow, so I can test it with MP!L.
This post was edited on 06-24-2006 at 03:32 PM by Matti.
|
|
06-24-2006 03:12 PM |
|
|
hmaster
Senior Member
Posts: 716 Reputation: 24
33 / /
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.
|
|
06-24-2006 03:34 PM |
|
|
surfichris
Former Admin
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 |
|
|
|
|