PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.php > extract a part of string from other string
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
extract a part of string from other string

Réponse
 
LinkBack Outils de la discussion
Vieux 13/11/2007, 15h34   #1
artev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut extract a part of string from other string

I would like to extract a piece of string inner oneother;
how rule for extraction all text inner this ">.......</a>


example if I have this string
<li><a href="http://localhost/namesitos/index.php?pg=id=b8f">Title &amp;
Test</a></li>

the code will return Title &amp; Test
  Réponse avec citation
Vieux 14/11/2007, 19h16   #2
Tom
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract a part of string from other string

On Tue, 13 Nov 2007 16:34:18 +0100, artev wrote...
>
>I would like to extract a piece of string inner oneother;
>how rule for extraction all text inner this ">.......</a>
>
>
>example if I have this string
><li><a href="http://localhost/namesitos/index.php?pg=id=b8f">Title &amp;
>Test</a></li>
>
>the code will return Title &amp; Test




You can use preg_replace() similar to this...

<?php

$string = '<li><a href="http://localhost/namesitos/index.php?pg=id=b8f">Title
&amp; Test</a></li>' ;

echo preg_replace('/<li><a href\=.+>(.+)<\/a>\<\/li>/', "$1", $string);

?>


Tom
--
NewsGuy Free Trial Accounts
Now a massive 20 Gigabytes of unrestricted downloads !
http://newsguy.com/

  Réponse avec citation
Vieux 16/11/2007, 11h10   #3
BoneIdol
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: extract a part of string from other string

On 14 Nov, 19:16, Tom <t...@to.com> wrote:
> On Tue, 13 Nov 2007 16:34:18 +0100, artev wrote...
>
> >I would like to extract a piece of string inner oneother;
> >how rule for extraction all text inner this ">.......</a>

>
> >example if I have this string
> ><li><a href="http://localhost/namesitos/index.php?pg=id=b8f">Title &amp;
> >Test</a></li>

>
> >the code will return Title &amp; Test

>
> You can use preg_replace() similar to this...
>
> <?php
>
> $string = '<li><a href="http://localhost/namesitos/index.php?pg=id=b8f">Title
> &amp; Test</a></li>' ;
>
> echo preg_replace('/<li><a href\=.+>(.+)<\/a>\<\/li>/', "$1", $string);
>
> ?>
>
> Tom
> --
> NewsGuy Free Trial Accounts
> Now a massive 20 Gigabytes of unrestricted downloads !http://newsguy.com/


If you're just wanting to strip all the html from input (and I mean
strip, not escape with entities) just use strip_tags(). I haven't used
it in a long time, but I seem to recall that it would leave the text
between tags unmolestred.

http://www.php.net/strip-tags
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 09h57.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13338 seconds with 11 queries