简体   繁体   中英

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.

您没有转义正确的字符,请尝试以下操作:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM