这完美地运作:
$replaceLyrics=str_replace
(
'story',
'_____',
'The story of my life I take her home I drive all night to keep her warm and time Is frozen (the story of, the story of)'
);
echo $replaceLyrics;
Run Code Online (Sandbox Code Playgroud)
输出:
The _____ of my life I take her home I drive all night to keep her warm and time Is frozen (the _____ of, the _____ of)
Run Code Online (Sandbox Code Playgroud)
我的问题是,是否可以使用内部php功能来仅替换匹配中的第一个匹配而不是全部替换.
我期待得到这个输出:
The _____ of my life I take her home I drive all night to keep …Run Code Online (Sandbox Code Playgroud) 我想知道是否有任何“开箱即用”的 php 函数可以对字符串中的所有字符进行编码,而不仅仅是空格。
$str="Encode All Characters Not Only The Spaces In Between";
echo rawurlencode($str);
Run Code Online (Sandbox Code Playgroud)
这返回:
Encode%20All%20Characters%20Not%20Only%20The%20Spaces%20In%20Between
Run Code Online (Sandbox Code Playgroud)
但我想对所有字符串进行编码,而不仅仅是空格。
我想只获取没有任何参数的url的"清洁"版本.IOW ...如果网址内有问号,请将其删除,然后删除所有内容.
这是我目前的行:
preg_match_all('/<a(.*?)href=("|\'|)(.*?)("|\'| )(.*?)>/s',$content,$ahref);
Run Code Online (Sandbox Code Playgroud)
而且在这里要更清楚......我期待这个网址(例如):
/go/page/mobile_download_apps.html?&who=r,6GDewh28SCW3/fUSqmWqR_E9ljkcH1DheIMqgbiHjlX3OBDbskcuCZ22iDvk0zeZR7BEthcEaXGFWaQ4Burmd4eKuhMpqojjDE6BrCiUtLClkT32CejpMIdnqVOUmWBD
Run Code Online (Sandbox Code Playgroud)
将会 :
/go/page/mobile_download_apps.html
Run Code Online (Sandbox Code Playgroud) php ×3
string ×3
arrays ×1
encode ×1
foreach ×1
preg-match ×1
regex ×1
str-replace ×1
urlencode ×1
utf-8 ×1