preg-replace

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1

放肆的年华 提交于 2020-01-29 13:33:26
问题 Can someone help debug this error? Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1 //Generate uid function gen_uid($len=40) { $hex = md5("what" . uniqid("", true)); $pack = pack('H*', $hex); $tmp = base64_encode($pack); $uid = preg_replace("#(*UTF8)[^A-Za-z0-9]#", "", $tmp); $len = max(4, min(128, $len)); while (strlen($uid) < $len) $uid .= gen_uid(22); return substr($uid, 0, $len); } What causes this? Is it a PHP issue or something else? The

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1

眉间皱痕 提交于 2020-01-29 13:32:17
问题 Can someone help debug this error? Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1 //Generate uid function gen_uid($len=40) { $hex = md5("what" . uniqid("", true)); $pack = pack('H*', $hex); $tmp = base64_encode($pack); $uid = preg_replace("#(*UTF8)[^A-Za-z0-9]#", "", $tmp); $len = max(4, min(128, $len)); while (strlen($uid) < $len) $uid .= gen_uid(22); return substr($uid, 0, $len); } What causes this? Is it a PHP issue or something else? The

Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1

我是研究僧i 提交于 2020-01-29 13:29:04
问题 Can someone help debug this error? Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 1 //Generate uid function gen_uid($len=40) { $hex = md5("what" . uniqid("", true)); $pack = pack('H*', $hex); $tmp = base64_encode($pack); $uid = preg_replace("#(*UTF8)[^A-Za-z0-9]#", "", $tmp); $len = max(4, min(128, $len)); while (strlen($uid) < $len) $uid .= gen_uid(22); return substr($uid, 0, $len); } What causes this? Is it a PHP issue or something else? The

Convert plain text URLs into HTML hyperlinks in PHP

折月煮酒 提交于 2020-01-26 08:46:54
问题 I have a simple commenting system where people can submit hyperlinks inside the plain text field. When I display these records back from the database and into the web page, what RegExp in PHP can I use to convert these links into HTML-type anchor links? I don't want the algorithm to do this with any other kind of link, just http and https. 回答1: Here is an other solution, This will catch all http/https/www and convert to clickable links. $url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+

PHP preg_replace() - Memory Issues. Alternative?

旧街凉风 提交于 2020-01-24 21:25:11
问题 In a site I'm working on, im converting strings to slugs using the answer in this question. It works, but I'm finding there are HUGE memory leak issues. I've done some research and found that this is just currently a bug in PHP. Are there any alternatives to accomplish something like strings to slug? EDIT: There's another interesting angle to this problem. I'm re-developing a scraper that was made using regex (ugh, i know), so I decided to use DOMDocument / XPath as a solution. The

PHP: Preg_replace, word boundaries and non word characters

送分小仙女□ 提交于 2020-01-23 13:00:07
问题 I need to replace words that start with hash mark (#) inside a text. Well I know how I can replace whole words. preg_replace("/\b".$variable."\b/", $value, $text); Because that \b modifier accepts only word characters so a word containing hash mark wont be replaced. I have this html which contains #companyName type of variables which I replace with a value. 回答1: \b matches between an alphanumeric character (shorthand \w ) and a non-alphanumeric character ( \W ), counting underscores as

use preg_replace to replace character unless an escape character precedes

為{幸葍}努か 提交于 2020-01-21 12:23:27
问题 i'm trying to do the following hope there's a reg_ex expert around to shed some light. I need to replace the character [ in my code and make it a {. But there is cases where the [ needs to remain a [ and not change. So the way i figured it is i need to use the preg_replace("[", "{", $string); function with a suitable regular expression that will result the [ characters that are not preceded by the escape character to be used lets say . So how can i get to replace this "[" and not this "["?

use preg_replace to replace character unless an escape character precedes

故事扮演 提交于 2020-01-21 12:23:05
问题 i'm trying to do the following hope there's a reg_ex expert around to shed some light. I need to replace the character [ in my code and make it a {. But there is cases where the [ needs to remain a [ and not change. So the way i figured it is i need to use the preg_replace("[", "{", $string); function with a suitable regular expression that will result the [ characters that are not preceded by the escape character to be used lets say . So how can i get to replace this "[" and not this "["?

Replace “//” with “/* */” in PHP? [closed]

我的未来我决定 提交于 2020-01-17 18:11:24
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm working in a code to minify html/css/js but i got a problem. I need to replace // with /* and */. Example: $(funcion(){ // Do something }); Replace to: $(funcion(){ /* Do something */ }); How do that? 回答1: First, as was pointed out in the comments, if you're looking to reduce

Replace “//” with “/* */” in PHP? [closed]

送分小仙女□ 提交于 2020-01-17 18:09:30
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I'm working in a code to minify html/css/js but i got a problem. I need to replace // with /* and */. Example: $(funcion(){ // Do something }); Replace to: $(funcion(){ /* Do something */ }); How do that? 回答1: First, as was pointed out in the comments, if you're looking to reduce