php: beautify var_export
2019-09-24
Die Ausgabe von var_export()
aufgehübscht.
Mit Rückgabe von array(..)
als Array Indikator
// prettify var_dump array
$sExport = var_export($mData, true);
$sExport = preg_replace("/^([ ]*)(.*)/m", '$1$1$2', $sExport);
$aData = preg_split("/\r\n|\n|\r/", $sExport);
$aData = preg_replace(["/\s*array\s\($/", "/\)(,)?$/", "/\s=>\s$/"], [NULL, ')$1', ' => array('], $aData);
$sExport = join(PHP_EOL […]
php: Extract URLs from String
2019-08-07
Q: How to extract URLs from a string with php ?
A: use the php function preg_match_all
to acvhieve this.
example
// example string with URLs
$sContent = 'https://blog.ueffing.net, FOO BAR BLA BLA https://www.ueffing.net/, BLA BLA https://github.com/gueff';
$sPattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
preg_match_all(
$sPattern,
$sContent, […]