當前位置:首頁 » 編程語言 » php字元串替換正則

php字元串替換正則

發布時間: 2023-02-13 01:53:24

『壹』 php 正則表達式替換字元

$str="{235大吉大利abc}";
$str=preg_replace("/[a-z,A-Z,0-9]/","*",$str);//替換所有字母和數字為*
echo$str;

『貳』 PHP 字元串替換 正則表達式 preg_match_all 方法

<?php
$a="floor(ceil(TC003*TC003)*price3+floor(20*(TC123+TC101))+(TC213+TC033)*tTC001000+pprice222+tc1)";

$out=preg_replace('/(?:TCd{3}|priced{1})(?!d)/i','1',$a);

echo'<pre>';
print_r($out);

//結果
//floor(ceil(1*1)*1+floor(20*(1+1))+(1+1)*tTC001000+pprice222+tc1)

『叄』 php 正則替換字元串問題

$contents = "aaaaaa aaa aaa aaa aaa";

$contents = preg_replace('/(\s+)aaa(\s?)/','b ',$contents);
$contents = preg_replace('/(\s+)aaa/','b',$contents);

『肆』 PHP正則表達式如何替換掉某字

<?php

$string='倚天屠龍記2019版粵語版';

$pattern='/版$/';

$replacement='';

echopreg_replace($pattern,$replacement,$string);

?>

$pattern='/版$/';正則表達式,匹配最後一個字是版.匹配第一個'版'。'/版/'。匹配所有的版'/版/g'。

$replacement='';用來替換的內容,去掉就是替換為空字元串。

更多需求查看php正則表達式教程網頁鏈接

『伍』 php字元串正則替換,我想把特殊字元換成逗號

對固定的字元串替換不要使用正則,使用str_replace既可,例如:

<?php
$a='/demo/uploads/2014/09/021421091017.jpg|,||-|/demo/uploads/2014/09/021421096757.jpg|,||-|';
$s=str_replace('|,||-|',',',$a);
echo$s;
?>

經過測試,結果復核你的要求。

『陸』 php如何進行正則替換

按照你的要求把h後的數字和w後的任意數字替換成固定數的php程序如下

<?php

$fix='555';//固定數

$str='asdasda/w/100/h/200/q/sdasdsad';

$regex1="~h/[0-9]+~";

$result=preg_replace($regex1,"h/".$fix,$str);

$regex2="~w/[0-9]+~";

$result=preg_replace($regex2,"w/".$fix,$result);

print_r($result);

?>
運行結果

asdasda/w/555/h/555/q/sdasdsad

『柒』 php正則替換字元串

$pattern
=
"/(?:http|https|ftp):\/\/\w+\.\w+\.(?:com|e|net)(?:\.cn)?/ie";

//直接通過正則進行替換

//(反向)後向引用(就是將之前查詢出的內容,在preg_replace的第二個參數當中去使用)

//$str
=
preg_replace($pattern,'<a
href="\\0">\\0</a>',$str);//推薦使用

$str
=
preg_replace($pattern,'\'<a
href="$0">\'.strtoupper("$0").\'</a>\'',$str);
正則需要自己寫
沒個人寫的正則都不一樣。希望採納

熱點內容
火車頭密碼指紋鎖多少錢 發布:2025-09-18 23:16:55 瀏覽:128
雪佛蘭最高配置長什麼樣 發布:2025-09-18 23:16:54 瀏覽:162
網路通話源碼 發布:2025-09-18 23:07:23 瀏覽:81
asp如何購買伺服器 發布:2025-09-18 22:46:24 瀏覽:665
網頁加密代碼 發布:2025-09-18 21:56:12 瀏覽:168
安卓targz解壓 發布:2025-09-18 21:45:58 瀏覽:803
怎麼設置手機屏幕密碼怎麼設置 發布:2025-09-18 21:44:18 瀏覽:820
直線插補演算法 發布:2025-09-18 21:22:49 瀏覽:657
矩陣內的演算法 發布:2025-09-18 20:55:07 瀏覽:574
android網路優化 發布:2025-09-18 20:53:19 瀏覽:220