Thursday 15 August 2013

php - Remove Non Standard character from begining or end of string -



php - Remove Non Standard character from begining or end of string -

i trying manipulate sentences, , can remove non standard characters string, there way if @ origin or end of string? remove non standard characters using following:

preg_replace("/[^a-za-z0-9 ]/", '', $string);

i alter string this:

"* sentence. --"

to this:

"this sentence."

this isn't 100% robust, works:

preg_replace("/(?:^[^a-z0-9]+|[^.a-z0-9]+$)/", "", $input_lines);

demo

basically, it's replacing either @ origin line isn't a-z, 0-9 '' (since there no matching groups) or (|) @ end after total stop isn't 0-9, a-z.

php

No comments:

Post a Comment