简体   繁体   中英

String function: preg-replace

I have not achieved result as expected. Here is what my string and code look like in PHP.

$string in text box

"This is 《Carriage Return》
a 《Carriage Return》
test"

Then using code in PHP:

$cleanstring=preg_replace('/\s+/', ' ', $string); //(' ' has a space in between)

Result came out as:

$cleanstring="This is\r\na\r\ntest"

But I expected it to be as "This is a test"

找到了有效的代码:

$cleanstring=trim(preg_replace('/\s{1,}/', ' ', $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