Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

PHP/REGEX: everything before certain characters

Using PHP and REGEX, I would like only everything before certain characters.

Everything after any of the following characters, including those characters, should be removed.

:
!
0
1
2
3
4
5
6
7
8
9
(


For example, this:
Hello World! This is a test.

Should become this:
Hello World

This:
Hi 123

Should become this:
Hi
ASKER CERTIFIED SOLUTION
Avatar of ragnarok89
ragnarok89

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hankknight

ASKER

Thanks!  Here is an example of the working code:
<?php

$data = 'Hello, world 0432! Zooph 123';
echo preg_replace('#[0-9:!(].*$#', '$1', $data );

?>

Open in new window