PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] What is the preg_replace regex to replace this HTML tag?

 November 20, 2022     html-parsing, php, preg-replace, regex     No comments   

Issue

How would I convert strings like this:

<span class="it">CONTENT</span>

Into this:

{it}CONTENT{/it}

While keeping CONTENT intact?


Solution

preg_replace('/<span class="it">(.*?)<\/span>/', '{it}$1{/it}', $text)

This is not the most versatile solution, but this works for your code. There is the possibility to have the content of the class attribute as a variable as well, but that won't be too hard to figure out now.



Answered By - Mave
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing