otak info official Logo   
OTAK.INFO
Personal Blog

Hariyanto Lim

정길상 / 鄭吉祥
Home   Last Posts  
 
Please login to see more topics and discussion categories.
 
goto main category list >> Software programming >> PHP

Title : Remove newline and anything in between tags
Total Reply : 1
Total View : 4472


Harry
Harry
Total thread: 131
Total reply: 50

Post #143
Remove newline and anything in between tags
Below is the code snippet to create "safe" OL tags, this code is part of XSS (Cross-site scripting) attack prevention, it is only provided as a based to work on complete feature.

'
'.str_replace('
', ' ', '
function replace_ol_callback($matches) {
/**
* This function is to called from
* $safeHTML = preg_replace_callback('(
    (.*?)
)is', 'replace_ol_callback', $safeHTML);
*/

// NOTE : $matches[1] == the
    's attributes which will be REMOVED/IGNORED
    $content = '<ol>'.trim($matches[2]).'
'; // trim() is very important to remove newlines !!!

// NEXT STEPS are to replace other tags within
    ...

// NOTE: pay very close attention to the priority based on WHICH will come first

// 1. replace "
  1. " == remove anything between <ol>...<li...>
    $content = preg_replace('(<ol>(.*?)<li(.*?)>)is', '<ol><li>', $content);

    // 2. replace "
  2. " == remove anything between

  3. $content = preg_replace('(
  4. )is', '
  5. ', $content);

    // 3. replace "
" == remove anything between </li>...</ol>
$content = preg_replace('(</li>(.*?)</ol>)is', '</li></ol>', $content);

return $content;
}
').'
'
Falling in love with the world

Write : 2013-10-29 11:28:50
Last edit : 2013-10-29 11:42:24

Harry
Harry
Total thread: 131
Total reply: 50

Post #144
xXx
Reply #1
xXx
Falling in love with the world

Write : 2013-11-01 20:27:37
Last edit : 2013-11-01 20:28:14

If you want to create a new reply then please login first.



www.OTAK.INFO
Since 19 January 2007
Page hit : 937,062

Code update 24th June 2013
Brain is a very capable to solve big problems
but requires constant reminders about how to.
peace bird