[ create a new paste ] login | about

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

PHP, pasted on Jul 7:
1
2
3
4
5
6
7
8
9
10
11
<?php

define(URL_CONSTANT, '/');

function replace($article_id,$text){
    $pattern = '/\{\{(.*?)\}\}/';
    $replacement = '<img src="'.URL_CONSTANT.'articles/'.$article_id.'/'.'${1}'.'"></img>';
    return preg_replace($pattern, $replacement, $text);
}

echo replace(42, 'hello {{something.jpg}}');


Output:
1
hello <img src="/articles/42/something.jpg"></img>


Create a new paste based on this one


Comments: