preg-replace

Preg_replace and preg_match to get and replace HTML / PHP content

空扰寡人 提交于 2020-01-07 13:36:31
问题 I need to extract some HTML / PHP content and put it into an array. Here is what I have The code below is within a string called $string for example. <html> <?php myclass->my_function('First', 'Last'); ?> <p>Some other content</p> <?php myclass->my_function(1, 2, 3); ?> </html> I want to find all the values from the functions and sum them into an array with preg_match. Only myclass->my_function function values should be found. The array should look like this $array = array( 1 => array('First'

Preg_replace and preg_match to get and replace HTML / PHP content

浪子不回头ぞ 提交于 2020-01-07 13:36:11
问题 I need to extract some HTML / PHP content and put it into an array. Here is what I have The code below is within a string called $string for example. <html> <?php myclass->my_function('First', 'Last'); ?> <p>Some other content</p> <?php myclass->my_function(1, 2, 3); ?> </html> I want to find all the values from the functions and sum them into an array with preg_match. Only myclass->my_function function values should be found. The array should look like this $array = array( 1 => array('First'

match specific word between brackets

南楼画角 提交于 2020-01-07 08:33:10
问题 I need match and replace specific word between brackets (including the brackets). something like this: xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I need replace this: (xxxxSPECIFICWORDxxxxxxxxxxx) my text looks something like this: xx(xxxx)xxxx(xxxxxxxx)xxx(xxx)xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I tried write regex with preg_replace the problem that it replace all the text from the first bracket to my last specific word bracket. I realy don't know what to do can someone help me? thanks. 回答1: Dennis

match specific word between brackets

瘦欲@ 提交于 2020-01-07 08:32:06
问题 I need match and replace specific word between brackets (including the brackets). something like this: xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I need replace this: (xxxxSPECIFICWORDxxxxxxxxxxx) my text looks something like this: xx(xxxx)xxxx(xxxxxxxx)xxx(xxx)xxx(xxxxSPECIFICWORDxxxxxxxxxxx)xxx I tried write regex with preg_replace the problem that it replace all the text from the first bracket to my last specific word bracket. I realy don't know what to do can someone help me? thanks. 回答1: Dennis

php preg_replace: find links and add a #hash to it?

◇◆丶佛笑我妖孽 提交于 2020-01-06 13:05:10
问题 i have the following structure... $output = '<li><a href="http://forum.example.org">Something</a></li>' Actually $output holds multiple list-items. What's the best and easiest way to apply a #hash to each links href? as in... <li><a href="http://forum.example.org#something">Something</a></li> Any idea how to solve that? edit: btw it should always be the same #hash not as you might think in this example above, the #something is equal to the name of the link. So it should be #something for each

php preg_replace: find links and add a #hash to it?

别等时光非礼了梦想. 提交于 2020-01-06 13:04:05
问题 i have the following structure... $output = '<li><a href="http://forum.example.org">Something</a></li>' Actually $output holds multiple list-items. What's the best and easiest way to apply a #hash to each links href? as in... <li><a href="http://forum.example.org#something">Something</a></li> Any idea how to solve that? edit: btw it should always be the same #hash not as you might think in this example above, the #something is equal to the name of the link. So it should be #something for each

Get hashtag from string and get into meta keywords and tags

元气小坏坏 提交于 2020-01-06 10:51:04
问题 I'm creating a kind of a blog sharing link. Basically, for each link i would extract hashtag from post string and put it into a meta tags and keywords. So, string normally is like this #helloworld #test #video #youtube Bon Iver are the best daily surprise :D Now, how can i get only hashtags and insert into a string like this ? $hashtags = helloworld,test,video,youtube And after insert hashtags in meta tag <meta name="keywords" content="<? echo $hashtags ?>" > <meta name="tags" content="<?

Allowing at most 2 newline in textarea

故事扮演 提交于 2020-01-06 04:50:28
问题 I want to allow at most 2 newline characters in a text area. I want this solution in PHP or in PHP+JavaScript/jQuery. When ever the users enter more than 2 newline they will be replaced by 2 newline characters. The Input: 0 1 2 3 4 whatever i tried and failed <html> <form name="f" method="post"> 1 <textarea name="t"> <?php if (isset($_POST['t'])) { $t2 = $_POST['t']; $t3 = $_POST['t']; $t4 = $_POST['t']; echo $_POST['t']; } ?> </textarea> <br> 2 <textarea name="t2"> <?php if (isset($_POST['t'

PHP preg match / replace?

谁说胖子不能爱 提交于 2020-01-06 02:11:19
问题 I need to read the string $mysting and replace all incident of e.x. <img src="dummypic.jpg alt="dummy pic"> with <img src="dummypic.jpg alt="dummy pic" title="dummy pic"> in other words add the title where it is missing, and make the title tag have the same value as the alt tag. some incident my have additional parameters like border, with, height - and these should be left untouched ... 回答1: Rather than a regex, have a look into PHP DOMDocument to modify attributes, especially if there will

preg_replace any style tags expression

被刻印的时光 ゝ 提交于 2020-01-05 06:50:14
问题 I am trying to use preg_replace to remove any thing contained in a style tag. For example: <img src="image.jpg" style="float:left;" /> Would be changed to: <img src="image.jpg" /> Likewise: <a href="link.html" style="color:#FF0000;" class="someclass">Link</a> Would be changed to: <a href="link.html" class="someclass">Link</a> How would I write this regular expression? preg_replace('EXPRESSION', '', $string); 回答1: This should work: preg_replace("@(<[^<>]+)\sstyle\=[\"\'][^\"\']+[\"\']([^<>]+>)