PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > Re: [PHP] Regex to catch <p>s
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Re: [PHP] Regex to catch <p>s

Réponse
 
LinkBack Outils de la discussion
Vieux 06/05/2008, 04h45   #1
Ryan S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Regex to catch <p>s



<clip>
> To say I suck at regex is an understatement so really need any I can get on this, I have a page of text with different html tags in them, but each "block" of text has a <p> or a < class="something"> tag... anybody have any regex that will catch each of these paragraphs and put then into an array



If you're using php5 you can use DOM's getElementsByTagName.

If you still think you need to do some sort of regex it is possible
but it will be buggy at best.


</clip>

Nope, need a regex... guess I have no choice, either chancy regex or nothing... I know for a fact that the first paragraph tag wont contain a class, and for the <p> tags that contain a class="blah" does it matter that i know exactly what the classname is?



__________________________________________________ __________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ
  Réponse avec citation
Vieux 06/05/2008, 19h00   #2
Shawn McKenzie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] Regex to catch <p>s

Ryan S wrote:
>
> <clip>
>> To say I suck at regex is an understatement so really need any I can get on this, I have a page of text with different html tags in them, but each "block" of text has a <p> or a < class="something"> tag... anybody have any regex that will catch each of these paragraphs and put then into an array

>
>
> If you're using php5 you can use DOM's getElementsByTagName.
>
> If you still think you need to do some sort of regex it is possible
> but it will be buggy at best.
>
>
> </clip>
>
> Nope, need a regex... guess I have no choice, either chancy regex or nothing... I know for a fact that the first paragraph tag wont contain a class, and for the <p> tags that contain a class="blah" does it matter that i know exactly what the classname is?
>
>
>
> __________________________________________________ __________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ


preg_match_all('|<p[^>]*>(.*)</p>|Ui', $myText, $myArray);
  Réponse avec citation
Vieux 06/05/2008, 19h52   #3
vester_s
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Re[PHP] gex to catch <p>s


$tag_regex=array(
'/\<p(\s*)\>(.*?)\<\/p\> /si' => "$1",
'/\<(\s*)(*.?)class\=(*.?)\>(.*?)\<\/(*.?)\>/si' => "$3"
);

$paragraphs=preg_replace(array_keys($tag_regex),ar ray_values($tag_regex),$page);

I am not sure what tag is that you mean on <class="something">, but in this
RE .. it should capture any <p> tags (the first element of the array) and
any tags (the second element of the array) that has attribute class on it.

You can find another example of this kind of HTML parsing in the PHP... try
googling it..

HTH


Ryan S-4 wrote:
>
>
>
> <clip>
>> To say I suck at regex is an understatement so really need any I
>> can get on this, I have a page of text with different html tags in them,
>> but each "block" of text has a <p> or a < class="something"> tag...
>> anybody have any regex that will catch each of these paragraphs and put
>> then into an array

>
>
> If you're using php5 you can use DOM's getElementsByTagName.
>
> If you still think you need to do some sort of regex it is possible
> but it will be buggy at best.
>
>
> </clip>
>
> Nope, need a regex... guess I have no choice, either chancy regex or
> nothing... I know for a fact that the first paragraph tag wont contain a
> class, and for the <p> tags that contain a class="blah" does it matter
> that i know exactly what the classname is?
>
>
>
>
> __________________________________________________ __________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now.
> http://mobile.yahoo.com/;_ylt=Ahu06i...Dypao8Wcj9tAcJ
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>


--
View this message in context: http://www.nabble.com/Re%3A-Regex-to...p17089906.html
Sent from the PHP - General mailing list archive at Nabble.com.

  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 12h15.


É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,13999 seconds with 11 queries