我正试图删除重复的斜杠,当我绑它时,我得到错误.似乎有些角色必须逃脱,但我不知道哪一个.
<?php
$path = preg_replace('(\\){2,}', '$1', 'z:\\\aaa\\\\bbb\c\ddd\');
echo $path;
?>
Run Code Online (Sandbox Code Playgroud)
这给了,
解析错误:语法错误,意外T_ENCAPSED_AND_WHITESPACE
有人可以解决这个问题吗?
我正在尝试创建将输入字符串的代码,搜索某些字符的字符串并用html代码替换它们.
这就是我到目前为止所做的
function htmlsymbolsconvertor($tmp1)
{
$symbols = array ('£', '-');
$htmlcode = array ('£', '-');
return preg_replace($symbols, $htmlcode, $tmp1);
}
Run Code Online (Sandbox Code Playgroud)
但是它不会将输入字符更改为html代码.
我可能没有理解使用preg_replace的php.net页面,我还没有找到任何已经有类似于我想要做的事情或我可以修改的东西.
虽然我不确定preg_replace是否是正确的PHP代码我需要使用.最终,一旦我得到代码工作符号和htmlcode将被放入数据库,但我可以轻松地做到这一点,我只需要让基本代码工作.
如果stackoverflow上有另一个主题,涵盖了我的要求,请指出我为重复道歉.
我有以下preg_replace()功能定位链接:
$link = preg_replace(
"#http://([\S]+?)#Uis", '<a href="http://\\1">(link)</a>',
$link
);
Run Code Online (Sandbox Code Playgroud)
它适用于http链接,但显然没有https链接.如何调整它以便它也适用于https链接.
我正在尝试替换URL列表的会话ID#
例如:http://www.yes.com/index.php? session = e4bce57bc39f67bebde0284f4c2ed9ba&id = 1234
我正试图摆脱这session=e4bce57bc39f67bebde0284f4c2ed9ba一点,只是保持http://www.yes.com/index.php?id=1234一点.
我正在尝试使用:
preg_replace('&\bhttp://www\.yes\.com/(?:index\.php(?:\?id(?:=[]\d!"#$%\'()*+,./:;<=>?@[\\\\_`a-z{|}~^-]*+)?&i', $subject, $regs))
Run Code Online (Sandbox Code Playgroud)
但这不起作用.任何帮助,将不胜感激.谢谢!
我正在使用preg_replace()如下代码中所示.
$p = preg_replace('/#[\d\w]+/', '<a href="http://'.$_SERVER['HTTP_HOST'].'/search/term:'.str_replace('#', rawurlencode('%23'), '${1}').'">${1}</a>', $p);
$p will be a string like '(#ben)'
Run Code Online (Sandbox Code Playgroud)
但是,没有输出任何内容$1.我使用$1不正确吗?
应该输出这个: <h2>Bens (<a href="http://example.com/search/term:#ben">ben</a>) cat</h2>
我尝试从字符串中删除此符号.我试试这个:
$string = preg_replace('`', '', $string);
Run Code Online (Sandbox Code Playgroud)
但得到:
No ending delemiter ''发现'
我做错了什么?
我如何将<i> </i>标签包裹在下面的This is line one!, This is line two!,周围,结果是:This is line three!$thisStr
`<i>This is line one!</i>`
`<i>This is line two!</i>`
`<i>This is line three!</i>`
Run Code Online (Sandbox Code Playgroud)
我所做的只是在::零件周围贴上标签。我无法让它后退和前进并包裹标签。
$thisStr = 'This is line one! :: This is line two! :: This is line three!';
echo preg_replace("/(::)/i", "<i>$1</i>", $thisStr);
考虑
preg_replace('/(lets go).*/', "going", "lets go somewhere")
Run Code Online (Sandbox Code Playgroud)
它将输出:"前进",我想"去某个地方".
preg_replace似乎用第一个匹配替换,这是整个字符串"让我去某个地方".如何使它忽略索引0并仅忽略目标索引1?
如果数字小于 10,我想创建一个带有前导零的分页: < 07 08 09 10 11 >
我的分页输出类似的 HTML:
<div>
<a href="#"><</a>
<span>7</span>
<a href="#">8</a>
<a href="#">9</a>
<a href="#">10</a>
<a href="#">11</a>
<a href="#">></a>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用该preg_replace函数来捕获个位数并添加前导零,但我不知道如何保留该数字:
$r = preg_replace('/>[0-9]</', '>01<', $r);
return $r;
Run Code Online (Sandbox Code Playgroud)
我解决了这个问题,str_replace但这很丑陋:
$r = str_replace(array('>1<','>2<','>3<','>4<','>5<','>6<','>7<','>8<','>9<'), array('>01<','>02<','>03<','>04<','>05<','>06<','>07<','>08<','>09<'), $r);
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个正则表达式preg_replace在大括号之间的字符串中,后跟$符号以这种方式:
{$string} //match
{$123string} //match
{string} //no match
{$string123} //match
[$string] //no match
Run Code Online (Sandbox Code Playgroud) 我有一个名为 list.txt 的文件,我想将字母“a”放在前面,将字母“b”放在列表中每一行的后面。
我想用"|"替换":" 在这种情况下:
$path="C:/example";
Run Code Online (Sandbox Code Playgroud)
我想要$path像"C|/example"
我在尝试 preg_replace('/:/',"|", $path);
php ×12
preg-replace ×12
regex ×7
arrays ×1
escaping ×1
leading-zero ×1
pagination ×1
pipe ×1
syntax-error ×1
yii ×1