Last active
March 1, 2020 16:36
-
-
Save mkdesignn/99e3422e0d1ed8a66ae2af5cfa0e2035 to your computer and use it in GitHub Desktop.
Clean the text regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$text = '[IMG][img]https://i.imgur.com/hyj2oZBh.png[/img][/IMG] | |
[IMG][img]https://i.imgur.com/removed.png[/IMG][/img] | |
<iframe width="640" height="360" src="https://www.youtube.com/embed/HdYg2EPMKiI?rel=0" frameborder="0" allowfullscreen></iframe> | |
<iframe height="560" width="40" src="https://www.youtube.com/embed/Xt2lHsDZSYs?rel=0" frameborder="0" allowfullscreen></iframe> | |
<iframe src="https://www.verticalscope.com/"></iframe> | |
This is on a 2013 70s edition. I have a video of the problem on youtube if you search. [h]Should remove code without options too[/h]. [h=1]2013 VW Beetle DAB NOT WORKING![/h]'; | |
function cleanTheTextFirstSolution($text) | |
{ | |
return preg_replace( | |
['/<iframe(.*)embed\//', '/\?rel(.*)iframe>/', '/\[h\]/', '/\[\/h\]/', '/\[h=[\w\d]\]/', '/\[img\]\[img\]/i', '/\[\/img\]\[\/img\]/i'], | |
['[MEDIA=youtube]' , '[/MEDIA]' , '' , '' , '' , '[img]' , '[/img]'] , $text); | |
} | |
function cleanTheTextSecondSolution($text) | |
{ | |
return preg_replace( | |
['/<iframe(.*)embed\//', '/\?rel(.*)iframe>/', '/\[h\]/', '/\[\/h\]/', '/\[h=[\w\d]\]/', '/IMG\]/', '/(\[img\])+\b/i', '/\b(\[\/img\])+/i'], | |
['[MEDIA=youtube]' , '[/MEDIA]' , '' , '' , '' , 'img]' , '$1' , '$1' ] , $text); | |
} | |
var_dump(cleanTheTextFirstSolution($text)); | |
var_dump(cleanTheTextSecondSolution($text)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment