Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP字符串修改需要帮助_Php_String_Character_Symbols - Fatal编程技术网

PHP字符串修改需要帮助

PHP字符串修改需要帮助,php,string,character,symbols,Php,String,Character,Symbols,我有一个具体的问题,我正在重新创建网站,我需要留下相同的广告网址。 也许有人有办法做到这一点: 租金:15K砂分离器。11“内径储罐,带3-1/16”15K流线。每月14750 为此: 租赁-15k-砂分离器-11-id-储罐-w-3-1-16-15k-流线-14-750-每月 我已尝试将所有字符更改为-但如果有更多符号,我会得到多个破折号。您可以执行双重替换: // Replace anything that is not letter or number to dash $string =

我有一个具体的问题,我正在重新创建网站,我需要留下相同的广告网址。 也许有人有办法做到这一点:

租金:15K砂分离器。11“内径储罐,带3-1/16”15K流线。每月14750

为此:

租赁-15k-砂分离器-11-id-储罐-w-3-1-16-15k-流线-14-750-每月


我已尝试将所有字符更改为-但如果有更多符号,我会得到多个破折号。

您可以执行双重替换:

// Replace anything that is not letter or number to dash
$string = preg_replace('/[^a-z0-9]/i', '-', $string);
// Replace more than one dash to single dash
$string = preg_replace('/-+/', '-', $string);
正如我所看到的,你是从一些产品名称的搜索引擎优化友好的网址。试着寻找