ereg_replace を preg_replace に書き換える - PHP

published: 2018.03.07 / modified:

ereg_replace 関数は正規表現による置換ができる。
ただ、この関数は PHP 5.3.0 で非推奨となっているようだ。

echo ereg_replace('https?:/{2,}', '', 'http://example.com');
// example.com

そのため、 ereg_replace の代替えとして preg_replace 関数を使ってみることにする。

echo preg_replace('/https?:\/{2,}/', '', 'http://example.com');
// example.com

Previous Article

Next Article