Forum Moderators: coopster
Hi ABC100! My score on FB-101 is 3,100. Marker is 700. My seat number is 5 at 1000 row.
The script should return:
[i]Hi ABC100 My score on FB-101 is Marker is My seat number is at row[i]
My code is here:
function stripAll($stext)
{
$clean=preg_replace('/[^A-Za-z0-9\s]*/', '',$stext);
return $clean;}
I tried inserting several pattern but still can't get it to work. It either removes all the numbers or not at all.
Thanks in advance for the help.
You'd think you could just use word boundary to capture FB-101, but it interprets the 101 after - as a boundary. Anyway this is a bit convoluted but works.
<?php
header("content-type:text/html");
$str = 'Hi ABC100! My score on FB-101 is 3,100.
Marker is 700. My seat number is 5 at 1000 row.';
echo "<p>$str</p>";
$str = stripAll($str);
echo "<p><strong>Stripped:</strong> $str</p>";
function stripAll($stext) {
if (!$stext) { return ''; }
$stext=preg_replace('/[^a-z\d\s\-]+|\b[^\w\-]+\d+,*\d*\.*\d*\b/i','',$stext);
return $stext;
}
?>
Be sure the change the | to an actual logical or pipe. The convolut-edness in the second half should support decimal numbers too, untested.
EDIT: WOO HOO! Brett let us have our pipes back! :-P
It works with a bit of problem. I noticed the following:
Message Input:
Memo REF 09-501: Out of 100 people, ABC100 got 10th place on 100 days, 15.7 average.
Output:
Memo REF-501 Out of people ABC100 got 10th place on days 157 average
Message Input:
10 Memo REF 09-501: Out of 100 people, ABC100 got 10th place on 100 days, 15.7 average.
Output:
10 Memo REF-501 Out of people ABC100 got 10th place on days 157 average
Should be Output:
Memo REF 09-501 Out of people ABC100 got 10th place one days average
Thanks for the time.