Jump to content

Php regular expression help


colap

Recommended Posts

<pre>
<pre class="brush:cpp">
<pre class="brush:javascript">

Those can be cpp,javascript,python ... etc.

 

I need to change/replace these into:

 

<pre>
<pre class="brush:cpp">
<pre class="brush:javascript">

Those can be cpp,javascript,python ... etc.

 

I need a generic regular expression for this? Can anyone provide the generic regular expression for this to replace?

 

Trying=>

$abc = str_replace(array($generic-regular-expression),'<pre> or <pre class="brush:cpp"> or <pre class="brush:javascript"> ..... ',$str);

Link to comment
https://forums.phpfreaks.com/topic/255951-php-regular-expression-help/
Share on other sites

Then you're going to need to provide more information. Show a sample of the data before and after, and explain what should be changed, and what should be left as is, and why.

 

Look at my original question. There i have told that it will be changed into <pre class="brush:cpp">. Though html_entity_decode does this job, but i don't want to do html_entity_decode for <br/> and other html elements. Other html elements will be as those were. Only you have to convert it to <pre class="brush:cpp">. But if i do html_entity_decode($alltexts); it converts all html element, that's not what i want.

I have looked at your original question yet again, and every html entity in it was indeed converted. There were no <br> tags or any other tags that were not converted, nor did you state anything like, "these are the only tags I want converted; the others should be left as-is", that's why I asked for more information. Your question was rather ambiguous.

to back pika up, since iv'e read this thread several times now. According to the contents of your original post, html_entity_decode is the perfect, simplest solution for this. So unless you took the code from the op out of context (which doesn't make sense if you want a correct answer the first time), you have your answer.

I have looked at your original question yet again, and every html entity in it was indeed converted. There were no <br> tags or any other tags that were not converted, nor did you state anything like, "these are the only tags I want converted; the others should be left as-is", that's why I asked for more information.

 

The texts will not only contain <pre class="brush:cpp"> but also contain like <br&gt and other escaped form of html element, i need to convert only the pre tag not other html escaped tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.