开发者

Replace string using php preg_replace

开发者 https://www.devze.com 2023-02-27 18:33 出处:网络
Hi all i know preg_replace can be used for formatting string but i need help in that concerned area my url will be like this

Hi all i know preg_replace can be used for formatting string but i need help in that concerned area my url will be like this

http://www.ex开发者_运维技巧ample.com/index.php/

also remove the http,https,ftp....sites also

what i want is to get result as

example.com/index.php


echo preg_replace("~(([a-z]*[:](//))|(www.))~", '', "ftp://www.example.com");


$url = 'http://www.example.com/index.php/';
$strpos = strpos($url,'.');
$output = substr($url,$strpos+1);


$parts=parse_url($url);
unset($parts['scheme']);
//echo http_build_url($parts);   
echo implode("",$parts);

EDIT

To use http_build_url you needs pecl_http you can use implode as alternate


Something like this

  $url = "http://www.example.com/index.php";
  $parts = parse_url($url);
  unset($parts['scheme']);

  echo preg_replace('/^((ww)[a-z\d][\x2E])/i', '', join('', $parts));

Output

example.com/index.php

Example #2

$url = "http://ww3.nysif.com/Workers_Compensation.aspx";

Output

nysif.com/Workers_Compensation.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号