Php 如何替换“✦;”字符串中的所有域名性格?
我得到的最多的是:Php 如何替换“✦;”字符串中的所有域名性格?,php,Php,我得到的最多的是: $name = str_replace("*.*", "✦", $name); 例如: $name = "Hello | google.com" 将被替换为: $name = "Hello | ✦" 尝试使用regex <?php preg_replace('/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i','
$name = str_replace("*.*", "✦", $name);
例如:
$name = "Hello | google.com"
将被替换为:
$name = "Hello | ✦"
尝试使用
regex
<?php
preg_replace('/\b(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/i','✦',$name);
?>
您可以使用
preg\u replace()
进行模式匹配替换
$name = "Hello | google.com";
//$name = preg_replace("/[a-zA-Z]+\.[a-zA-Z]+/", "✦", $name);
$name = preg_replace("/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])+/", "✦", $name);
echo $name;
欢迎来到堆栈溢出!请拿着这本书,四处看看,通读一遍,特别是你做了哪些研究?你具体被困在哪里?很好用,但有可能以某种方式将我自己的领域排除在外吗?