【问题标题】:Can you help me with preg_replace?你能帮我做preg_replace吗?
【发布时间】:2013-12-18 08:34:10
【问题描述】:

我必须将字符串的一部分替换为另一部分。

原文:

src="../../Estatico//ComunesSEI/Images/Supernet_logo.gif"

我想要的结果:

src="https://empresas3.gruposantander.es/SEI_PARTENON_ENS/Estatico//ComunesSEI/Images/Supernet_logo.gif"

问题:我必须改变

src="../..

 src="src="https://empresas3.gruposantander.es/SEI_PARTENON_ENS

【问题讨论】:

  • 欢迎来到 SO!你能解释一下你尝试了什么吗?
  • 我试过这个 $pattern = '/src="\/..\/..\//'; $replace = 'src="empresas3.gruposantander.es/SEI_PARTENON_ENS'; $output = preg_replace($pattern,$replace,$output);
  • 也尝试转义.。 src="\/\.\.\/\.\.\//';
  • 我不明白你的意思:S 你能解释一下或举个例子吗?这!

标签: url preg-replace


【解决方案1】:

你为什么不直接使用str_replace

$string = "../../Estatico//ComunesSEI/Images/Supernet_logo.gif";
$find = "../..";
$replace = "https://empresas3.gruposantander.es/SEI_PARTENON_ENS";

echo str_replace($find, $replcae $string);

【讨论】:

    猜你喜欢
    • 2017-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    相关资源
    最近更新 更多