Page 1 sur 1

Aide avec preg_match_all

Posté : 19 juin 2009, 03:50
par Invité
Bonjour,

Jessais de faire un preg_match_all mais je ne sais pas pourquoi il ne fonctionne pas. quelqu'un pourrait m'aider ?

le patern :
'pattern' => '@<a id="video-url-([^"]+)" href="/watch?v=([^"]+)" rel="nofollow"><img title="([^"]+)" src="([^"]+)" class="vimg120" qlicon="([^"]+)" alt="([^"]+)">@'
et voici la page ou j'utilise le patern :

Code : Tout sélectionner

"><div class="video-entry"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a id="video-url-ic5OkQkJM0U" href="/watch?v=ic5OkQkJM0U" rel="nofollow"><img title="A Tasteful Pursuit DC" src="http://i2.ytimg.com/vi/ic5OkQkJM0U/default.jpg" class="vimg120" qlicon="ic5OkQkJM0U" alt="A Tasteful Pursuit DC"></a><div id="quicklist-icon-ic5OkQkJM0U" class="addtoQL90"><a id="add-to-quicklist-ic5OkQkJM0U" href="#" ql="ic5OkQkJM0U" title="Add Video to QuickList"><button class="master-sprite QLIconImg" title=""onclick="clicked_add_icon(this, this.parentNode.getAttribute('ql'), 0, 'http://i2.ytimg.com/vi/ic5OkQkJM0U/default.jpg', 'A Tasteful Pursuit DC');return false;"onmouseover="mouseOverQuickAdd(this)"onmouseout="mouseOutQuickAdd(this)"onmousedown="urchinTracker('/Events/results/QuickList+AddTo')"></button><div class="hid quicklist-inlist"><a href="/watch_queue?all">Added</a></div></div><div class="video-time"><span id="video-run-time-ic5OkQkJM0U">2:51</span></div></div></div></div><div class="video-main-content" id="video-main-content-ic5OkQkJM0U"><div class="video-title video-title-results"><div class="video-short-title"><span id="translated_short_prefix_ic5OkQkJM0U" style="font-size: 10px;" class="hid">[TRANSLATED]</span><a id="video-short-title-ic5OkQkJM0U" href="/watch?v=ic5OkQkJM0U" title="A Tasteful Pursuit DC" rel="nofollow"><b>A</b> Tasteful Pursuit DC</a></div><div class="video-long-title"><span id="translated_long_prefix_ic5OkQkJM0U" style="font-size: 10px;" class="hid">[TRANSLATED]</span><a id="video-long-title-ic5OkQkJM0U" href="/watch?v=ic5OkQkJM0U" title="A Tasteful Pursuit DC" rel="nofollow"><b>A</b> Tasteful Pursuit DC</a></div></div><div id="video-description-ic5OkQkJM0U" class="video-description">Share Our Strength held its annual <b>A</b> Tasteful Pursuit dinner in Washington, DC earlier this month. Maryland Governor Martin O'Malley and US <b>...</b></div><div class="result-label"><span class="result-type">Video</span> from <span class="video-username"><a id="video-from-username-ic5OkQkJM0U" class="hLink" href="/user/ShareStrength">ShareStrength</a></span></div><div class="video-facets"><span id="video-average-rating-ic5OkQkJM0U" class="video-rating-list ">no rating</span><span id="video-added-time-ic5OkQkJM0U" class="video-date-added">7 hours ago</span><span id="video-num-views-ic5OkQkJM0U" class="video-view-count">0 views</span><span class="video-username"><a id="video-from-username-ic5OkQkJM0U" class="hLink" href="/user/ShareStrength">ShareStrength</a></span><span id="video-average-rating-ic5OkQkJM0U" class="video-rating-grid ">no rating</span></div></div><div class="video-clear-list-left"></div></div></div><div class="video-cell" style="width:19.6%"><div class="video-entry"><div class="v120WideEntry"><div class="v120WrapperOuter"><div class="v120WrapperInner"><a id="video-url--A35VUs4Suw" href="/watch?v=-A35VUs4Suw" rel="nofollow"><img title="How to Throw a Football" src="http://i2.ytimg.com/vi/-A35VUs4Suw/default.jpg" class="vimg120" qlicon="-A35VUs4Suw" alt="How to Throw a Football"></a><div id="quicklist-icon--A35VUs4Suw" class="addtoQL90"><a id="add-to-quicklist--A35VUs4Suw" href="#" ql="-A35VUs4Suw" title="Add Video to QuickList"><button class="master-sprite QLIconImg" title=""onclick="clicked_add_icon(this, this.parentNode.getAttribute('ql'), 0, 'http://i2.ytimg.com/vi/-A35VUs4Suw/default.jpg', 'How to Throw a Football');return false;"onmouseover="mouseOverQuickAdd(this)"onmouseout="mouseOutQuickAdd(this)"onmousedown="urchinTracker('/Events/results/QuickList+AddTo')"></button><div class="hid quicklist-inlist"><a href="/watch_queue?all">Added</a></div></div><div class="video-time"><span id="video-run-time--A35VUs4Suw">1:22</span></div></div></div></div><div class="video-main-content" id="video-main-content--A35VUs4Suw"><div class="video-title video-title-results"><div class="video-short-title"><span id="translated_short_prefix_-A35VUs4Suw" style="font-size: 10px;" class="hid">[TRANSLATED]</span><a id="video-short-title--A35VUs4Suw" href="/watch?v=-A35VUs4Suw" title="How to Throw a Football" rel="nofollow">How to Throw <b>a</b> Football</a></div><div class="video-long-title"><span id="translated_long_prefix_-A35VUs4Suw" style="font-size: 10px;" class="hid">[TRANSLATED]</span><a id="video-long-title--A35VUs4Suw" href="/watch?v=-A35VUs4Suw" title="How to Throw a Football" rel="nofollow">How to Throw <b>a</b> Football</a></div></div><div id="video-description--A35VUs4Suw" class="video-description">The quarterback runs the offense of <b>a</b> football team. Learn tips for throwing <b>a</b> spiral with <b>a</b> football in this coaching video from <b>a</b> professional <b>...</b></div><div class="result-label"><span class="result-type">Video</span> from <span class="video-username"><a id="video-from-username--A35VUs4Suw" class="hLink" href="/user/livestrong">livestrong</a></span></div><div class="video-facets"><span id="video-average-rating--A35VUs4Suw" class="video-rating-list ">no rating</span><span id="video-added-time--A35VUs4Suw" class="video-date-added">4 hours ago</span><span id="video-num-views--A35VUs4Suw" class="video-view-count">0 views</span><span class="video-username"><a id="video-from-username--A35VUs4Suw" class="hLink" href="/user/livestrong">livestrong</a></span><span id="video-average-rating--A35VUs4Suw" class="video-rating-grid ">no rating</span></div></div><div class="video-clear-list-left"></div></div></div><div class="video-cell" style="width:19.6%"><
Merci beaucoup de votre aide.

PS. ne me collez pas juste le code j'aimerais bien ici comprendre l'erreur sinon sa va pas me servir !

Posté : 19 juin 2009, 15:13
par Nagol
quel pattern? :)

Posté : 19 juin 2009, 22:38
par Invité
<a id="video-url-([^"]+)" href="/watch?v=([^"]+)" rel="nofollow"><img title="([^"]+)" src="([^"]+)" class="vimg120" qlicon="([^"]+)" alt="([^"]+)">
Celui ci !
Merci d'avance !

Posté : 20 juin 2009, 15:20
par Nagol
oki; il est caché, la faute à phpbb qui scrolle pas au lieu de faire 4000px de largeur :)

donc il s'agit de parsing html, (déja fortement déconseillé) ce html ne serait pas du xml plutot? genre s'il est valide xhtml déja, tu auras moins de galère à le parser en xml qu'en html

si ce n'estpas le cas, je te conseille de parser en deux temps, d'abord d'écupères tous les lines dans un tableau avec un preg_match_all, ensuite boucle sur ton tableau, pour trouver ce qui t'intéresse, les preg_match_all c'est bien mais c'est sensible et très mal optimisé, tu auras de meilleures perf de le faire en deux temps, sans compter que ca sera plus facile à coder.