小编dav*_*rko的帖子

PHP强制str_replace只替换其中一个结果

这完美地运作:

$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 arrays string foreach str-replace

3
推荐指数
1
解决办法
589
查看次数

PHP 如何使用 rawurlencode 对所有字符进行编码

我想知道是否有任何“开箱即用”的 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)

但我想对所有字符串进行编码,而不仅仅是空格。

php string encode urlencode utf-8

1
推荐指数
1
解决办法
850
查看次数

PHP preg_match_all动态删除url参数

我想只获取没有任何参数的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 regex string preg-match-all preg-match

0
推荐指数
1
解决办法
138
查看次数