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

PHP,beautify,DE

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

PHP,string,array,EN

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,
    $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".