体验一下Adobe Dreamweaver 2021的PHP编辑功能

安装上后没有太大的惊喜,和phpStorm相比,类文件的定位还需要加强,总之先看一下吧。

我们发现有PHP代码片段功能,于是好奇测试一下“通过标题创建网址”的代码吧。

<?php
function create_slug($string, $charset = 'utf-8'){
$string = htmlentities($string, ENT_NOQUOTES, $charset, false); // convert accented characters to entities
// strip unwanted parts of entities to leave unaccented character
$string = preg_replace('~&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);~', '\1', $string);
$string = preg_replace('~&([A-za-z]{2})(?:lig);~', '\1', $string);
$string = preg_replace('~&[^;]+;~', '', $string); // remove other entities
return preg_replace('~[\s!*\'();:@&=+$,/?%#[\]]+~', '-', $string); // replace spaces and illegal characters with hyphens
}
echo create_slug("This is a sample test")."<br>"; //returns 'This-is-a-sample-test'
echo create_slug("L'été? est là &amp; &eacute;");// returns 'L-ete-est-la-e'
?>

测试发现标题转网址的代码有BUG,并未对~波浪线进行处理,以下是修复后的代码:

function create_slug($string, $charset = 'utf-8'){
    // convert accented characters to entities
    $string = htmlentities($string, ENT_NOQUOTES, $charset, false);
    // strip unwanted parts of entities to leave unaccented character
    $string = preg_replace('~&([A-za-z])(?:acute|cedil|caron|circ|grave|orn|ring|slash|th|tilde|uml);~', '\1', $string);
    $string = preg_replace('~&([A-za-z]{2})(?:lig);~', '\1', $string);
    // remove other entities
    $string = preg_replace('~&[^;]+;~', '', $string); 
    // replace spaces and illegal characters with hyphens
    $string = preg_replace('~["`\~\s!*\'();:@&=+$,/?%#[\]]+~', '-', $string); 
    $string = preg_replace('~[^\w\-]+~', '', $string); 
    $string = preg_replace('~-+~', '-', $string); 
    return trim($string, '-');
}
echo create_slug("This `~~。 \"‘’+—— ~ is a sample test")."<br>"; //returns 'This-is-a-sample-test'
echo create_slug("L'été? est là & é");// returns 'L-ete-est-la-e'

转载请注明出处:https://www.onexin.net/adobe-dreamweaver-2021-php/

相关文章:

1、用 PHP 编写更好的正则表达式regex
https://www.onexin.net/php-regex/

2、PHP 版本 8.2,8.1,8.0,7.4
https://www.onexin.net/php-8_2-8_1-8_0-7_4/

3、PHP中的Liskov替换原则
https://www.onexin.net/php-liskov/

4、php实现自运行的do实例详解
https://www.onexin.net/php-do/

5、PHP 后端实现JWT认证方法示例
https://www.onexin.net/php-jwt/

Leave a Reply