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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.