Issue
i'm trying to get rid of a few character within a string:
"V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables."
I'd like to erase everything after (H/F) or (h/f) or H/F or F/H or f/h etc ...
I tried this but not working:
$offer = preg_replace(array('/ F\/\H.*/','/ (F\/\H).*/','/ H\/\F.*/','/ (H\/\F).*/'), '', $offer);
Any idea ? Thanks a lot from France !
Solution
Find the pattern \s*\(?(?:h/f|f/h)\)?.*$
and then replace with empty string:
$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;
This prints:
V.I.E Responsable Projets Marque Propre (H/F) – Roumanie (Bucarest) – 12 mois renouvelables.
V.I.E Responsable Projets Marque Propre
Answered By - Tim Biegeleisen Answer Checked By - Terry (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.