IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

utilisation regex et preg_replace [PHP 5.4]


Sujet :

Langage PHP

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 84
    Points : 83
    Points
    83
    Par défaut utilisation regex et preg_replace
    Bonjour,
    j'explique mon problème, j'ai une string:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    $texte='{
    	"costingImport.explication" : "You can include a cost breakdown sheet in <b>excel format (.xls or .xlsx)</b>."+
    		"<br> - If this cost breakdown sheet contains blocking errors, it will not be included and you will stay on this page. A list of the cells containing errors will appear."+
    		"<br> - If there isnt any blocking error, the cost breakdown sheet will be saved and will go to the next step (BEING CREATED). You will be redirected on the screen of the cost breakdown sheet."+
    		"<br> - If there is no possible attachment between a data on the sheet and the applications repository (example : non-existent material, supplier not referenced), this data will be deleted. You will have to update the settings of the application, then edit the cost breakdown sheet.",
    	"costingImport.btn.import": "Import",
    }';
    pour que je puisse faire mon affichage correctement, j'ai besoin de transformer la string ci-dessus en celle ci-dessous:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    $texte='{
    	"costingImport.explication" : "You can include a cost breakdown sheet in <b>excel format (.xls or .xlsx)</b>.
    		<br> - If this cost breakdown sheet contains blocking errors, it will not be included and you will stay on this page. A list of the cells containing errors will appear.
    		<br> - If there isnt any blocking error, the cost breakdown sheet will be saved and will go to the next step (BEING CREATED). You will be redirected on the screen of the cost breakdown sheet.
    		<br> - If there is no possible attachment between a data on the sheet and the applications repository (example : non-existent material, supplier not referenced), this data will be deleted. You will have to update the settings of the application, then edit the cost breakdown sheet.",
    	"costingImport.btn.import": "Import",
    }';
    visiblement un regex semble pouvoir résolver ce problème mais la ou je bloque c'est sur l'écriture de ce même regex qui ressemble mot pour mot au texte écrit dans ce smiley =>

    j'ai quand même tenté ma chance mais mon code manque visiblement de talent ^^'
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $texte2=preg_replace('/(?="+).*?(?=")/','',$texte);
    quelqu'un peut-il m'aider pour la syntaxe ?
    Sans pomme nous n'aurions jamais découvert la gravité... Sans tête Non plus.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    En devinant ce que tu voulais remplacer, je te propose :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    preg_replace("#\"[\+,]\r\n(\t+)\"#", "\r\n$1", $texte);
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Janvier 2015
    Messages
    84
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 29
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Janvier 2015
    Messages : 84
    Points : 83
    Points
    83
    Par défaut
    oui c'est exactement ça merci
    Sans pomme nous n'aurions jamais découvert la gravité... Sans tête Non plus.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Récupérer la valeur entre 2 balises en utilisant Regex
    Par new123 dans le forum Général Java
    Réponses: 5
    Dernier message: 08/04/2011, 10h38
  2. [RegEx] utilisation regex pour pagination articles
    Par peaulisse dans le forum Langage
    Réponses: 2
    Dernier message: 19/03/2010, 21h37
  3. utilisation regex \d
    Par osnet dans le forum Langage
    Réponses: 8
    Dernier message: 18/08/2009, 18h23
  4. Utiliser Regex pour remplacement
    Par soveste dans le forum Collection et Stream
    Réponses: 13
    Dernier message: 19/03/2007, 09h48
  5. [Notepad++] utiliser regex pour remplacer des caractères
    Par ilood dans le forum Autres Logiciels
    Réponses: 2
    Dernier message: 04/02/2007, 04h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo