Remove Everything After Character Pattern Preg_Replace Regex expression

Monday, 23. July 2012

A little snippet that simply removes everything after a matched pattern using preg_replace regular expression.

Example

# remove everything after TEL: symbol
$address = "John Scott, Leeds, UK. TEL: 000111-234 345";
# new address
$new_address = preg_replace('/TEL:.*/i', '', $address, -1, $count);

Enjoy!

Leave a Reply

You must be logged in to post a comment.