php: beautify var_export
2019-09-24 2019-12-30 00:24:31


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, array_filter(["array("] + $aData));

_Angelehnt an Or […]

php: Extract URLs from String
2019-08-07 2019-12-30 00:24:21


Q: How to extract URLs from a string with php ?

A: use the php function preg_match_all to acvhieve this.


// example string with URLs
$sContent = ', FOO BAR BLA BLA, BLA BLA';

$sPattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
    $aMatch, // <= saves result into $aMatch
    PR […]

This website uses Cookies to provide you with the best possible service. Please see our Privacy Policy for more information. Click the check box below to accept cookies. Then confirm with a click on "Save".