[英]Remove slash str_replace PHP
即时通讯试图从字符串中删除不需要的字符,但我无法弄出斜杠/一个。
$url = "http://www.google.com/";
$array_remove = array(
'/',
' ',
'-',
'.'
);
$string = "This i Will convert to-Picture/sting";
$convert = $url.'images/'.strtolower(str_replace($array_remove, '_',$string).'.gif');
在这种情况下,斜杠将保留在那里,结果将是: this_i_will_convert_to_picture/string.gif
但需要是this_i_will_convert_to_picture_string.gif
非常感谢您在此提供的任何帮助或提示。
您的代码在5.4.0版中可以完美运行。
试试preg_replace:
$string = preg_replace('(\/)', '_', $string);
echo "<br />string:".$string."<br />";
您是否可能从POST获取数据?
转换不想在这种情况下工作,所以我更改了方案以保存最终字符串并在需要的地方使用。
是同一件事,但是在这种情况下可以工作。
$url = "http://www.google.com/";
$array_remove = array(
'/',
' ',
'-',
'.'
);
$string = "This i Will convert to-Picture/sting";
$converted = strtolower(str_replace($array_remove, '_', $string));
$convert = $url.'images/'.$converted.'.gif';
优秀的! 您的代码可以完美运行。
运行此代码:
$url = "http://www.google.com/";
$array_remove = array( '/', ' ', '-', '.' );
$string = "This i Will convert to-Picture/sting";
echo "string: ".$string."<br />";
$converted = strtolower(str_replace($array_remove, '_', $string));
echo "converted: ".$converted."<br />";
$convert = $url.'images/'.$converted.'.gif';
echo "convert: ".$convert."<br />";
并且您的输出应为:
字符串:这我将转换为图片/ sting
已转换:this_i_will_convert_to_picture_sting
转换: http : //www.google.com/images/this_i_will_convert_to_picture_sting.gif
或您得到什么输出?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.