Php : comment remplacer chaine de caractères?
Résolu
JessayeDeTrouver
Messages postés
270
Date d'inscription
Statut
Membre
Dernière intervention
-
Zep3k!GnO Messages postés 2025 Date d'inscription Statut Membre Dernière intervention -
Zep3k!GnO Messages postés 2025 Date d'inscription Statut Membre Dernière intervention -
Bonjour, j'ai un une variable $texte qui est égale à ceci :
$texte='
<a href="https://www.commentcamarche.net/">ccm</a>
<a href="https://www.google.fr/?gws_rd=ssl">google</a>';
Et moi je cherche le code php qui permet d'ajouter un target="_blank" à chaque lien détecté
càd que $texte devient égal à
$texte='
<a href="https://www.commentcamarche.net/" target="_blank">ccm</a>
<a href="https://www.google.fr/?gws_rd=ssl" target="_blank">google</a>';
Donc est-ce quelqu'un aurait la solution.
Merci 1000 fois d'avance, cdt.
$texte='
<a href="https://www.commentcamarche.net/">ccm</a>
<a href="https://www.google.fr/?gws_rd=ssl">google</a>';
Et moi je cherche le code php qui permet d'ajouter un target="_blank" à chaque lien détecté
càd que $texte devient égal à
$texte='
<a href="https://www.commentcamarche.net/" target="_blank">ccm</a>
<a href="https://www.google.fr/?gws_rd=ssl" target="_blank">google</a>';
Donc est-ce quelqu'un aurait la solution.
Merci 1000 fois d'avance, cdt.
A voir également:
- Php : comment remplacer chaine de caractères?
- Easy php - Télécharger - Divers Web & Internet
- Expert php pinterest - Télécharger - Langages
- Retour a la ligne php - Forum Webmastering
- Alert php - Forum PHP
- Retour a la ligne php ✓ - Forum PHP
3 réponses
preg_replace : https://www.php.net/manual/fr/function.preg-replace.php
preg_replace('/(a href="[^"]+")(>)/i', '$1 target="_blank" $2', $texte);