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

php: find a value in multidimensional array
2019-08-03
IN1, 2019-08-03 00:00:00
IN1, 2023-04-10 14:16:30


Q: given a multidimensional array. how can i find a value in it ?

A: use the php function array_search in conjunction with array_column to solve this.

usage example

$aData = [
    'aKeyValue' => [
        0 => [
                'sKey' => 'sOldname',
                'sValue' => '/media/foo.txt',
            ],
        1 => [
                'sKey' => 'sNewname',
              […]


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