开发者

Simple strip in PHP

I'm looking for a really simple of way stripping content from this开发者_运维百科 string:

Example:

/m/NEEDED/

I would like to strip everything except "NEEDED".

Any help would be great, Thanks!


The str_replace() one is quite specific, and the one I'd use.

But since you mentioned strip(), it reminded me of trim():

echo trim('/m/NEEDED/','/m');

Example: http://codepad.viper-7.com/AcDZCM


$str = "/m/NEEDED/";
$newStr = preg_replace("~(/m/|/)~", "", $str);

demo

OR

$str = "/m/NEEDED/";
$newStr = preg_replace("|/(.*?)/(.*?)/|", "$2", $str);

demo

OR

$str = "/m/NEEDED/";
$newStr = str_replace(array('/', 'm'), "", $str);

demo


<?php
   $strip = array("/","m");
   echo str_replace($strip,"","text input here");
?>

Add more characters that you want to strip in the array if you want.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜