Hi, I have written a function which will replace a string like:
with the following
The problem with this function is that I cannot run this on the entire page, since it would just return the first button.
So I need help.
I need a function that will check a string of text for the following combination: {- some text -}
And then replace that string with the output from the function.
It's important that the content between {- and -} can be changed, since the content acts as "variables" for my function.
<?PHP
function replaceText($str){
$dat = explode('{-',$str);
$dat = explode('-}',$dat[1]);
$dat = explode('|',$dat[0]);
foreach($dat as $id => $str){
$out = explode(':',$str);
$new[$out[0]] = $out[1];
}
if($new['type']=='button') return '<input type="button" class="button" href="popup.php?r='.$new['info'].'" value="'.$new['text'].'" />';
if($new['type']=='link') {
$http = 'http://';
if($new['secure']=='yes') $http = 'https://';
return '<a class="button" href="'.$http.$new['link'].'" target="'.$new['target'].'">'.$new['text'].'</a>';
}
}
$str_1 = '{-type:button|info:item|text:Read more about item-}';
$str_2 = '{-type:link|target:blank|link:www.google.com|secure:no|text:Read more about item-}';
$str = $str_1.$str_2;
echo replaceText($str_1).'<br />';
echo replaceText($str_2).'<br />';
echo replaceText($str).'<br />';
?>