preg-replace

how to select image src using PHP

随声附和 提交于 2020-01-15 18:52:12
问题 So i have some images with several forms like this : <a href="" class="link-img" alt=""> <img editable="true" style="display: block; cursor: default;" class="main-image" width="538" height="auto" src="src" alt="large image"> </a> and like this : <a href="" class="link link-img"> <img src="src" style="width: 100%; display: block; cursor: pointer;" editable="true" class="main-image imageLink" width="" height="auto" alt=""> </a> so my code to select the src image is : $c = preg_replace('/<a href

Using PHP DOM want to show all string as a output

邮差的信 提交于 2020-01-15 09:41:09
问题 Here, is my html string in $data variable in php, and that string have some text like <140/90 mmHg OR <130/80 mmHg this line not showing when i run this code using PHP DOMDocument because when coming less-than & grater-than signs its problematic. <?php $data = 'THE CORRECT ANSWER IS C. <p>Choice A Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s</p> <p></p> <p>Choice B Lorem Ipsum is simply

PHP PREG_REPLACE Returning wrong result depending on order checked

妖精的绣舞 提交于 2020-01-15 08:55:09
问题 I have stumbled upon a really odd bug with PHP's preg_replace function and some regex patterns. What I'm trying to do is replace custom tags delimited by brackets and convert them to HTML. The regex has to account for custom "fill" tags that will stay with the outputted HTML so that it can be replaced on-the-fly when the page loads (replacing with a site-name for instance). Each regex pattern will work by itself, but for some reason, some of them will exit the function early if preceded by

Problem Replacing Literal String \r\n With Line Break in PHP

◇◆丶佛笑我妖孽 提交于 2020-01-15 08:01:08
问题 I have a text file that has the literal string \r\n in it. I want to replace this with an actual line break (\n). I know that the regex /\\r\\n/ should match it (I have tested it in Reggy), but I cannot get it to work in PHP. I have tried the following variations: preg_replace("/\\\\r\\\\n/", "\n", $line); preg_replace("/\\\\[r]\\\\[n]/", "\n", $line); preg_replace("/[\\\\][r][\\\\][n]/", "\n", $line); preg_replace("/[\\\\]r[\\\\]n/", "\n", $line); If I just try to replace the backslash, it

strip_tags: strip off the messy tags and styles

依然范特西╮ 提交于 2020-01-15 06:58:06
问题 How can I strip off certain html tags and allow some of them? For instance, I want to strip off span tags but allow the span with underline. <span style="text-decoration: underline;">Text</span> I want to allow p but I want to remove any styles or classes inside the p for instance, <p class="99light">Text</p> the class inside the p tag should be removed - I just want a clean p tag. The is the line I have so far, strip_tags($content, '<p><a><br><em><strong><ul><li>'); 回答1: You can't. You'll

How to replace Numbers in Parentheses with some calculations in MS Word

非 Y 不嫁゛ 提交于 2020-01-13 19:24:10
问题 I have a problem to replace some serial number such as [30] [31] [32]... to [31] [32] [33]... in MS word when I insert a new references in the middle of article. I have not found a solution way in GUI so I try to use VBA to do that replacement. I find a similar problem in stack overflow: MS Word Macro to increment all numbers in word document However, this way is a bit inconvenient because it have to generate some replacement array in other place. Can I make that replacement with regex and

How can I use PHP's preg_replace function to convert Unicode code points to actual characters/HTML entities?

我怕爱的太早我们不能终老 提交于 2020-01-13 19:15:10
问题 I want to convert a set of Unicode code points in string format to actual characters and/or HTML entities (either result is fine). For example, if I have the following string assignment: $str = '\u304a\u306f\u3088\u3046'; I want to use the preg_replace function to convert those Unicode code points to actual characters and/or HTML entities. As per other Stack Overflow posts I saw for similar issues, I first attempted the following: $str = '\u304a\u306f\u3088\u3046'; $str2 = preg_replace('/\u[0

Trouble Replacing Apostrophe with Preg_Replace

北城以北 提交于 2020-01-12 03:24:07
问题 I am attempting to remove apostrophes from text and it isn't really working. It's got to be something small. $text = preg_replace('/\'/', '', $text); That's what I am using right now to remove it. What am I doing wrong? There is a series of these to remove special characters to turn them into urls and store them in my database. However, a recent batch appeared with a ' where the ' was. Any help is greatly appreciated. Thank you in advance. 回答1: Have a go using str_replace(), it's quicker than

PHP 7 preg_replace PREG_JIT_STACKLIMIT_ERROR with simple string

与世无争的帅哥 提交于 2020-01-11 13:16:07
问题 I know other people have submitted questions around this error, however I can't see how this regex or the subject string could be any simpler. To me this is a bug, but before submitting it to PHP I thought I'd make sure and get help to see if this can be simpler. Here's a small test script showing 2 strings; one with 1024 x's and one with 1023: // 1024 x's $str = '

preg_replace, str_replace and substr_replace not working in special condition

泪湿孤枕 提交于 2020-01-11 11:38:06
问题 I have the following code: this code finds all html tags in a string and replaces them with [[0]], [[1]] ,[[2]] and so on.(at least that is intented but not workinng); $str = "some text <a href='/review/'>review</a> here <a class='abc' href='/about/'>link2</a> hahaha"; preg_match_all("|<[^>]+>(.*)</[^>]+>|U",$str, $out, PREG_OFFSET_CAPTURE); $count = 0; foreach($out[0] as $result) { $temp=preg_quote($result[0],'/'); $temp ="/".$temp."/"; preg_replace($temp, "[[".$count."]]", $str,1); $count++