[ create a new paste ] login | about

Link: http://codepad.org/C21eGIag    [ raw code | output | fork ]

PHP, pasted on Aug 13:
1
2
3
4
5
6
7
8
9
10
11
<?php
    function replace_matches($matches) {
        $text = htmlspecialchars($matches[1]);
        $url = urlencode($matches[1]);
        return "<a href=\"/story.php?urdu={$url}\">{$text}</a>";
    }    
    $str = "this is [my] test [string] and [<script>alert(1)</script>] is very long [with] so many pwords]";
    $str = preg_replace_callback("%\[(.+?)\]%", "replace_matches", $str);
    
    echo $str;
?>


Output:
1
this is <a href="/story.php?urdu=my">my</a> test <a href="/story.php?urdu=string">string</a> and <a href="/story.php?urdu=%3Cscript%3Ealert%281%29%3C%2Fscript%3E">&lt;script&gt;alert(1)&lt;/script&gt;</a> is very long <a href="/story.php?urdu=with">with</a> so many pwords]


Create a new paste based on this one


Comments: