- ob_start: documentation ( source)
- preg_quote: documentation ( source)
- preg_replace: documentation ( source)
<?php
//this code will append a &mobileapp to every url
ob_start(function($buffer){
$append = 'mobileapp';
$domain = '(?:'.preg_quote('example.com/~hillybilly')
.'|'.
'(?.*?\.)?'.preg_quote('foobar.com')
.')';
$buffer = //str_replace('example.com/~mydir/', 'w00t', $buffer);// preg_replace('/\b(https?:\/\/'.$domain.')([a-z0-9\._\/\~%\-\+&\#!=\(\)@]*)?([?])?([a-z0-9\._\/\~%\-\+&\#!=\(\)@]*)?/im', '$1$2?'.$append.'&$4', $buffer);
$regex = '/\b(https?:\/\/'.$domain
.'\/?)([a-z0-9\._\/~%\-\+&\#!=\(\)@]*)?([?])?([a-z0-9\._\/~%\-\+&\#!=\(\)@]*)?/igm';
$buffer = preg_replace($regex, '$1$2?'.$append.'&$4', $buffer);
return $buffer;
});
?>
http://foobar.com
http://www.example.com/~hillybilly/foobar.php