PHP - 删除字符并连接另一个字符的函数(也就是相对于绝对值的转换 url)
PHP - Function to remove character and concatenate another (aka converting relative to absolute url)
我有一个 phpbb 外部脚本,它输出一个相对 url
(喜欢./forum/viewtopic.php?f=xx&t=xx
),
但是为了制作 rss 提要,我需要绝对 url
(http://example.com/forum/viewtopic.php?f=xx&t=xx
) 使用。
我的问题是:我该怎么做?
我想它应该只是一个字符串函数,用于替换第一个点,然后连接它之前的 http://example.com
,但我没有足够的 php 技能来做到这一点。
只需将您的 ./
替换为主机名即可。
$url = str_replace('./', 'http://example.com/', $url);
我有一个 phpbb 外部脚本,它输出一个相对 url
(喜欢./forum/viewtopic.php?f=xx&t=xx
),
但是为了制作 rss 提要,我需要绝对 url
(http://example.com/forum/viewtopic.php?f=xx&t=xx
) 使用。
我的问题是:我该怎么做?
我想它应该只是一个字符串函数,用于替换第一个点,然后连接它之前的 http://example.com
,但我没有足够的 php 技能来做到这一点。
只需将您的 ./
替换为主机名即可。
$url = str_replace('./', 'http://example.com/', $url);