php: beautify var_export
2019-09-24
IN1, 2019-09-24 00:00:00
IN1, 2023-04-10 14:16:30


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
IN1, 2019-08-07 00:00:00
IN1, 2023-04-10 14:16:30


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, […]


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