如何擦除字符串以及 PHP 中的内容?
How to erase a string and what comes after in PHP?
我正在尝试删除字符串中的几个字符:
"V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables."
我想删除 (H/F) 或 (h/f) 或 H/F 或 F/H 或 [=29= 之后的所有内容]等...
我试过了但没有用:
$offer = preg_replace(array('/ F\/\H.*/','/ (F\/\H).*/','/ H\/\F.*/','/ (H\/\F).*/'), '', $offer);
有什么想法吗?非常感谢来自法国!
找到模式 \s*\(?(?:h/f|f/h)\)?.*$
然后替换为空字符串:
$input = "V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables.";
$output = preg_replace("/\s*\(?(?:h\/f|f\/h)\)?.*$/i", "", $input);
echo $input . "\n" . $output;
这会打印:
V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables.
V.I.E Responsable Projets Marque Propre
我正在尝试删除字符串中的几个字符:
"V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables."
我想删除 (H/F) 或 (h/f) 或 H/F 或 F/H 或 [=29= 之后的所有内容]等...
我试过了但没有用:
$offer = preg_replace(array('/ F\/\H.*/','/ (F\/\H).*/','/ H\/\F.*/','/ (H\/\F).*/'), '', $offer);
有什么想法吗?非常感谢来自法国!
找到模式 \s*\(?(?:h/f|f/h)\)?.*$
然后替换为空字符串:
$input = "V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables.";
$output = preg_replace("/\s*\(?(?:h\/f|f\/h)\)?.*$/i", "", $input);
echo $input . "\n" . $output;
这会打印:
V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables.
V.I.E Responsable Projets Marque Propre