Kasra
Kasra

Reputation: 81

Wildcard in preg_replace

I have a form. I want when users fill the form with these content for example:

Word (in Spain)

or

Word2 (in England)

Automatically (in *) removed and saved in database like this:

Word1

or

Word2

I used this code:

$obj['String'] = trim(preg_replace( '(in /\(.*)\/)', '', $obj['String'] ));

but this code not working and my table in database filled blank.

Upvotes: 1

Views: 1295

Answers (1)

Toto
Toto

Reputation: 91488

You aren't escaping the right characters, have a try with:

$obj['String'] = preg_replace( '/\s*\(in .*\)\s*$/', '', $obj['String'] );

Upvotes: 1

Related Questions