PHP如何在做preg_replace的同时做base64encode [英] php how to do base64encode while doing preg_replace
本文介绍了PHP如何在做preg_replace的同时做base64encode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用preg_replace
查找BBCODE
并将其替换为HTML代码,
但是在执行此操作时,我需要base64encode
网址,该怎么办?
I am using preg_replace
to find BBCODE
and replace it with HTML code,
but while doing that, I need to base64encode
the url, how can I do that ?
我正在这样使用preg_replace
:
<?php
$bbcode = array('#\[url=(.+)](.+)\[/url\]#Usi');
$html = array('<a href="$1">$2</a>');
$text = preg_replace($bbcode, $html,$text);
如何base64encode
href
值,即$1
吗?
我尝试做:
$html = array('<a href="/url/'.base64_encode('{$1}').'/">$2</a>');
,但其编码为{$1}
,而不是实际链接.
but its encoding the {$1}
and not the actual link.
推荐答案
查看全文