使用PHP将URL转换为Slug
我正在使用下面的代码尝试转换为slug,但由于某些原因,它没有响应任何内容。我知道我遗漏了一些非常明显的东西。我不是在调用函数吗使用PHP将URL转换为Slug,php,jquery,replace,Php,Jquery,Replace,我正在使用下面的代码尝试转换为slug,但由于某些原因,它没有响应任何内容。我知道我遗漏了一些非常明显的东西。我不是在调用函数吗 <?php $string = "Can't You Convert This To A Slug?"; function clean($string) { $string = str_replace(' ', '-', $string); // Replaces all spaces with hyp
<?php
$string = "Can't You Convert This To A Slug?";
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
echo $string;
}
?>
代码退出函数后,您将进行回音
试着这样做:
function clean_string($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
$some = clean_string("Can't You Convert This To A Slug?");
echo $some;
function clean_me(&$string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
$some = "Can't You Convert This To A Slug?";
clean_me($some);
echo $some;
或者像这样:
function clean_string($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
$some = clean_string("Can't You Convert This To A Slug?");
echo $some;
function clean_me(&$string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
$some = "Can't You Convert This To A Slug?";
clean_me($some);
echo $some;
什么是slug?你在slug中覆盖的URL在哪里?@Shahar在WordPress
中的说法slug
是特定帖子的URL键。你永远不会调用该方法。。。添加clean($string)代码>在底部。