Извлечение текста по шаблону.

Тема в разделе "PHP", создана пользователем Levitt, 28 июл 2011.

Модераторы: latteo
  1. Levitt

    Levitt

    Регистр.:
    20 май 2008
    Сообщения:
    358
    Симпатии:
    36
    В общем имеем такой текст (часть исходного кода google images по запросу "ololo")
    PHP:
    '\x26prev\x3d/images%3Fq%3Dimgkeyimg%26um%3D1%26hl%3Den%26safe%3Doff%26sa%3DN%26biw%3D1280%26bih%3D709%26tbm%3Disch\x26ei\x3daC4xTsTDFtCi-gbq3tSBDQ',0,0);
    dyn.setResults([["/imgres?imgurl\x3dhttp://www.print-post.jp/common/images/top_page/img_key_img.jpg\x26imgrefurl\x3dhttp://www.print-post.jp/\x26usg\x3d__uqgffUfHeWpw0ypdsR8rgAI3MXU\x3d\x26h\x3d203\x26w\x3d570\x26sz\x3d103\x26hl\x3den\x26start\x3d1\x26zoom\x3d1\x26um\x3d1\x26itbs\x3d1","","Su_HvQ8ymNMbsM:","","134","48","プリントポストがお客様に評価","","","570 ×
    203 - 103k"
    ,"jpg","print-post.jp","","","http://t3.gstatic.com/images","0",[],"",1,"#",[],"http://t3.gstatic.com/images?q\x3dtbn:ANd9GcQ_xanPw3EGbO7wmYJBn1aqzTPvMpmnb4jbV3cQC62pdFCg7MzxFbpZcqI","","","","","","","/search?q\x3dimgkeyimg\x26um\x3d1\x26hl\x3den\x26safe\x3doff\x26sa\x3dN\x26biw\x3d1280\x26bih\x3d709\x26tbm\x3disch\x26tbs\x3dsimg:CAQSEglK78e9DzKY0yHMtZBs8UbznA","More sizes","",[]],["/imgres?imgurl\x3dhttp://www.kawada.jp/global/img/key_img_003.jpg\x26imgrefurl\x3dhttp://www.kawada.jp/global/index.html\x26usg\x3d__6bkaryKXaMejbaFkOKTMWkX9SOY\x3d\x26h\x3d253\x26w\x3d942\x26sz\x3d118\x26hl\x3den\x26start\x3d2\x26zoom\x3d1\x26um\x3d1\x26itbs\x3d1","","bUZk4eNTjuhlHM:","","148","40",[B]"Serving Society Through"[/B],"","","942 ×
    253 - 118k"
    ,"jpg","kawada.jp","","","http://t0.gstatic.com/images","0",[],"",1,"#",[],"http://t0.gstatic.com/images?q\x3dtbn:ANd9GcTHxANTbgYcBuzIbI9AWwhz2Yu0ogGGcuTuLl5qfYHTamlDdUS3ILnVIs-R","","","","","","","/search?q\x3dimgkeyimg\x26um\x3d1\x26hl\x3den\x26safe\x3doff\x26sa\x3dN\x26biw\x3d1280\x26bih\x3d709\x26tbm\x3disch\x26tbs\x3dsimg:CAQSEgltRmTh41OO6CEfTZJBS05Muw","More sizes","",[]],["/imgres?imgurl\x3dhttp://avleentelecommunication.com/img/key-img.jpg\x26imgrefurl\x3dhttp://avleentelecommunication.com/key.html\x26usg\x3d__ksYUS4wYXvJjJLMzb8YW3IxmSyA\x3d\x26h\x3d301\x26w\x3d387\x26sz\x3d30\x26hl\x3den\x26start\x3d3\x26zoom\x3d1\x26um\x3d1\x26itbs\x3d1","","PUUBBJorWoz95M:","","123","96",[B]"AVLEEN TELECOMMUNICATION"[/B],"","","387 ×
    Нужно из него вытянуть описания к картинкам "プリントポストがお客様に評価","Serving Society Through" , "AVLEEN TELECOMMUNICATION" . Я вижу реализацию преобразованием через explode в массив и последующую выдачу определенного номера элемента этого массива. Вот, только незадача с шаблоном для отбора элементов для этого массива.
     
  2. t0os

    t0os

    Регистр.:
    21 окт 2007
    Сообщения:
    284
    Симпатии:
    36
    Это чтоли все одной строкой идет? Всегда в одинаковых BB-кодах описание к картинкам?
     
  3. zzallexx

    zzallexx

    Регистр.:
    11 июн 2008
    Сообщения:
    1.035
    Симпатии:
    703
    сначало експлодь через ; или × а потом уже через запятую
    PHP:
    <?php
    $content
    ='"/imgres?imgurl\x3dhttp://www.print-post.jp/common/images/top_page/img_key_img.jpg\x26imgrefurl\x3dhttp://www.print-post.jp/\x26usg\x3d__uqgffUfHeWpw0ypdsR8rgAI3MXU\x3d\x26h\x3d203\x26w\x3d570\x26sz\x3d103\x26hl\x3den\x26start\x3d1\x26zoom\x3d1\x26um\x3d1\x26itbs\x3d1","","Su_HvQ8ymNMbsM:","","134","48","プリントポストがお客様に評価","","","570 &times;
    203 - 103k","jpg","print-post.jp","","","http://t3.gstatic.com/images","0",[],"",1,"#",[],"http://t3.gstatic.com/images?q\x3dtbn:ANd9GcQ_xanPw3EGbO7wmYJBn1aqzTPvMpmnb4jbV3cQC62pdFCg7MzxFbpZcqI","","","","","","","/search?q\x3dimgkeyimg\x26um\x3d1\x26hl\x3den\x26safe\x3doff\x26sa\x3dN\x26biw\x3d1280\x26bih\x3d709\x26tbm\x3disch\x26tbs\x3dsimg:CAQSEglK78e9DzKY0yHMtZBs8UbznA","More sizes","",[]],["/imgres?imgurl\x3dhttp://www.kawada.jp/global/img/key_img_003.jpg\x26imgrefurl\x3dhttp://www.kawada.jp/global/index.html\x26usg\x3d__6bkaryKXaMejbaFkOKTMWkX9SOY\x3d\x26h\x3d253\x26w\x3d942\x26sz\x3d118\x26hl\x3den\x26start\x3d2\x26zoom\x3d1\x26um\x3d1\x26itbs\x3d1","","bUZk4eNTjuhlHM:","","148","40",[B]"Serving Society Through"[/B],"","","942 &times;
    253 - 118k","jpg","kawada.jp","","","http://t0.gstatic.com/images","0",[],"",1,"#",[],"http://t0.gstatic.com/images?q\x3dtbn:ANd9GcTHxANTbgYcBuzIbI9AWwhz2Yu0ogGGcuTuLl5qfYHTamlDdUS3ILnVIs-R","","","","","","","/search?q\x3dimgkeyimg\x26um\x3d1\x26hl\x3den\x26safe\x3doff\x26sa\x3dN\x26biw\x3d1280\x26bih\x3d709\x26tbm\x3disch\x26tbs\x3dsimg:CAQSEgltRmTh41OO6CEfTZJBS05Muw","More sizes","",[]],["/imgres?imgurl\x3dhttp://avleentelecommunication.com/img/key-img.jpg\x26imgrefurl\x3dhttp://avleentelecommunication.com/key.html\x26usg\x3d__ksYUS4wYXvJjJLMzb8YW3IxmSyA\x3d\x26h\x3d301\x26w\x3d387\x26sz\x3d30\x26hl\x3den\x26start\x3d3\x26zoom\x3d1\x26um\x3d1\x26itbs\x3d1","","PUUBBJorWoz95M:","","123","96",[B]"AVLEEN TELECOMMUNICATION"[/B],"","","387 &times; '
    ;
    $array explode(';',$content);
    //print_r($array);
    foreach ($array as $str){
    $descr=explode(',',$str);
    //print_r($descr);
    echo $descr[29]."<br>";
    }