php preg_replace yardıma ihtiyacım var

2 Cevap

now i want make this by the preg_replace

$web = 'site.com';

i want the preg_replace make it http://www.site.com and if it http://site.com no prblem it whould add http:// in it found in the url thanks

please i want do that is http:// not exsist

2 Cevap

Bunun için düzenli ifadeler gerekmez. Sadece do $web = "http://$web".

if( 0 !== strpos( $web, 'http://' ) )
{
    $web = 'http://'.$web;
}

Temelde, bir düzenli ifade gerekmez. Bu ne yapmalıyım 'http://' $web ilk parçası olup olmadığını görmek için kontrol edin. Değilse, o dizenin başına 'http://' katacak. Aksi takdirde, hiçbir şey yapmaz.

Bunu yapmak için başka bir yol sadece false ise işlev başarısız olursa ... if( false === strpos( $web, 'http://' ) ) Bu yürütmek gerektiğini kontrol etmektir. Ancak, bunu yapmak için en iyi yol olduğunu sanmıyorum.