Possible Duplicate: RegEx match open tags except XHTML self-contained tags I have the following string: $str = " <li>r</li> <li>a</li> <li>n</li> <li>d</li> ... <li>om</li> "; How do I get the HTML for the first n-th <li> tags? Ex : n = 3 ; result = "<li>r<...>n</li>; I would like a regexp if po
可能重复: RegEx匹配除XHTML自包含标签之外的开放标签 我有以下字符串: $str = " <li>r</li> <li>a</li> <li>n</li> <li>d</li> ... <li>om</li> "; 如何获取第一个第n个<li>标签的HTML? Ex : n = 3 ; result = "<li>r<...>n</li>; 如果可能,我想要一个正则表达式。 喜欢这个。 $dom = new DOMDocument(); @$dom
This question already has an answer here: RegEx match open tags except XHTML self-contained tags 35 answers preg_replace("{<img\s*(.*?)src=('.*?'|".*?"|[^\s]+)(.*?)\s*/?>}ims", '<a href=$2><img $1src=$2 $3/></a>', $str) handles all non-practical cases My I recommend the PHP DOM with loadHTML() instead of regex? http://php.net/d
这个问题在这里已经有了答案: RegEx匹配除XHTML自包含标签之外的开放标签35个答案 preg_replace("{<img\s*(.*?)src=('.*?'|".*?"|[^\s]+)(.*?)\s*/?>}ims", '<a href=$2><img $1src=$2 $3/></a>', $str) 处理所有非实际案例 我建议使用loadHTML()而不是正则表达式的PHP DOM? http://php.net/dom http://php.net/domdocument.loadhtml 我可以推荐使
Previously styled question: http://pastebin.com/cr432nLQ I've decided to rephrase the whole question about this problem and go as thoroughly as possible. You can read the previously asked question in the paste above. First of all, thanks to everyone for their responses, but unfortunately, they got me nowhere. I'm still in need of help for my problem. So, I'm using a jQuery plu
以前设计的问题:http://pastebin.com/cr432nLQ 我已经决定改写关于这个问题的整个问题,并尽可能彻底地去解决。 您可以阅读上面贴上的问题。 首先,感谢大家的回应,但不幸的是,他们让我无处可寻。 我仍然需要帮助解决我的问题。 所以,我使用了一个名为blueimp jQuery File Upload的jQuery插件,它非常好地处理异步文件上传,它包含很多选项。 这个插件对于我的目的来说足够好,但是我需要执行这个服务器端检查,以
I want to be able to validate a user's inputted regex, to check if it's valid or not. First thing I found with PHP's filter_var with the FILTER_VALIDATE_REGEXP constant but that doesn't do what I want since it must pass a regex to the options but I'm not regex'ing against anything so basically it's just checking the regex validity. But you get the idea, how do I val
我希望能够验证用户输入的正则表达式,以检查它是否有效。 首先我用PHP的filter_var发现了FILTER_VALIDATE_REGEXP常量,但这并不符合我的要求,因为它必须将正则表达式传递给选项,但我不会对任何东西进行正则表达式,所以基本上它只是检查正则表达式的有效性。 但是你明白了,我如何验证用户输入的正则表达式(与什么都不匹配)。 以简单的语言验证的例子: $user_inputted_regex = $_POST['regex']; // e.g. /([a-z]+)..*
Possible Duplicate: Test if a regular expression is a valid one in PHP <?php $subject = "PHP is the web scripting language of choice."; $pattern = 'sssss'; if(preg_match($pattern,$subject)) { echo 'true'; } else { echo 'false'; } ?> The above code gives me warning because the string $pattern is not a valid regular expression. If
可能重复: 测试一个正则表达式在PHP中是否有效 <?php $subject = "PHP is the web scripting language of choice."; $pattern = 'sssss'; if(preg_match($pattern,$subject)) { echo 'true'; } else { echo 'false'; } ?> 上面的代码给了我警告,因为字符串$pattern不是有效的正则表达式。 如果我通过有效的正则表达式,那么它工作正常..... 我如何检
Is there a good way of test if a string is a regex or normal string in PHP? Ideally I want to write a function to run a string through, that returns true or false. I had a look at preg_last_error() : <?php preg_match('/[a-z]/', 'test'); var_dump(preg_last_error()); preg_match('invalid regex', 'test'); var_dump(preg_last_error()); ?> Where obviously first one is not an error, and secon
有没有一种很好的方法来测试一个字符串是否是PHP中的正则表达式或普通字符串? 理想情况下,我想编写一个函数来运行一个字符串,它返回true或false。 我看了一下preg_last_error() : <?php preg_match('/[a-z]/', 'test'); var_dump(preg_last_error()); preg_match('invalid regex', 'test'); var_dump(preg_last_error()); ?> 显然,第一个不是错误,第二个是。 但preg_last_error()返回int 0 。 有任何想法吗
Possible Duplicate: Is there a regular expression to detect a valid regular expression? Regular expression for finding a regular expression? I have an application that enables the user to input a regular expression. How do I check against any input of regular expressions and make sure they are valid ones, because if they are not there there will be preg_match errors? I don't want to
可能重复: 是否有正则表达式来检测有效的正则表达式? 寻找正则表达式的正则表达式? 我有一个应用程序,使用户可以输入正则表达式。 我如何检查任何正则表达式的输入并确保它们是有效的,因为如果它们不在那里会出现preg_match错误? 我不想在preg_match之前使用'@',所以如果有办法检查正则表达式的用户输入的有效性,那将是非常好的。 PHP的正则表达式系统似乎太复杂了,我不能为它们提供一个正则表达式
I'd like to test the validity of a regular expression in PHP, preferably before it's used. Is the only way to do this actually trying a preg_match() and seeing if it returns FALSE ? Is there a simpler/proper way to test for a valid regular expression? // This is valid, both opening ( and closing ) var_dump(preg_match('~Valid(Regular)Expression~', null) === false); // This is invalid,
我想在PHP中测试正则表达式的有效性,最好在使用之前。 是否只有这样做才能真正尝试preg_match()并查看它是否返回FALSE ? 有没有更简单/正确的方法来测试有效的正则表达式? // This is valid, both opening ( and closing ) var_dump(preg_match('~Valid(Regular)Expression~', null) === false); // This is invalid, no opening ( for the closing ) var_dump(preg_match('~InvalidRegular)Expression~', null) === false
Having issues wish a preg_replace function. I am formatting a breadcrumb which the php is ioncubed so I am having to preg_replace to remove part of the breadcrumb. I have a breadcrumb that looks like <ul> <li><a href="mylink1.html">Link 1</a><i class="fa fa-angle-right"></i></li> <li><a href="mylink2.html">Link 2</a><i cl
有问题希望preg_replace函数。 我正在格式化一个面包屑,这是PHP离子切割,所以我不得不preg_replace删除部分面包屑。 我有一个面包屑,看起来像 <ul> <li><a href="mylink1.html">Link 1</a><i class="fa fa-angle-right"></i></li> <li><a href="mylink2.html">Link 2</a><i class="fa fa-angle-right"></i></li> <li>&
Possible Duplicate: Grabbing the href attribute of an A element Parse All Links That Contain A Specific Word In "href" Tag I'm using the following function to add _blank to all the links on my website. function targetBlank($text) { $return = str_replace('<a', '<a target="_blank"', $text); return $return; } I'm looking for a solution to apply this function only
可能重复: 抓取A元素的href属性 在“href”标签中解析包含特定字词的所有链接 我正在使用以下功能将_blank添加到我网站上的所有链接。 function targetBlank($text) { $return = str_replace('<a', '<a target="_blank"', $text); return $return; } 我正在寻找一种解决方案,将此功能仅应用于外部链接(而不是我的域)而不是所有链接。 以下是依赖于$_SERVER['HTTP_HOST']的尝试解决方案: function