0

I want to modify the withdrawal of an array of strings where the start and end are found

<?php


$file = ('http://gdata.youtube.com/feeds/base/users/BBCArabicNews/uploads?alt=rss&v=2&orderby=published&client=ytapi-youtube-profile'); 


$string=file_get_contents($file);
    function findinside($start, $end, $string) {
       preg_match_all('/' . preg_quote($start,'/') . '(.+?)'. preg_quote($end, '/').'/si', $string, $m);
        return $m[1];
    }
    $start = ':video:';
    $end = '</guid>';

    $out = findinside($start, $end, $string);

  $out = findinside($start, $end, $string);
foreach($out as $string){

  echo $string;
echo "<p></td>\n";

 }

?>

Results

Q80QSzgPDD8

ozei4GysBN8

ak3bbs_UxP0

rUs-r3ilTG4

p4BO6FI5sPY

j5lclrPzeVU

dK5VWTYsJaM

mERug-d536k

h0zqd3bC0-E

ije5kuSfLKY

H9XXMPvEpHM

EK5UoQqYl4U

This works properly in withdrawing of an array of strings I want to add also

  $start = '</pubDate><atom:updated>';
        $end = '</atom:updated>';

I want to be Show two array of strings Example

xSD0XJLkLQid
2011-11-08T17:36:14.000Z

bFU066NwVnD
2011-12-08T17:36:14.000Z

Can I do this with this code

Greetings

10neen com
  • 93
  • 7
  • Using regexes on XML/HTML is the wrong way to go. You should be using a DOM parser to retrieve the individual elements/tags and THEN you could use a regex or simple string manipulation to get your values: http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Marc B Nov 15 '11 at 17:42
  • I'm not sure I follow. What's the final output supposed to look like? – landons Nov 15 '11 at 17:42
  • Results in the end that I want to show the date and video code @landons – 10neen com Nov 15 '11 at 17:49
  • Ah. Yeah, you need a parser library: http://stackoverflow.com/questions/250679/best-way-to-parse-rss-atom-feeds-with-php – landons Nov 15 '11 at 17:57

2 Answers2

2

You can use PHP's DOMDocument parser like this:

$objDOM = new DOMDocument();
$objDOM->load($file);  // the long one from youtube
$dates = $objDOM->getElementsByTagName("pubDate"); 
foreach ($dates as $node)
{
     echo $node->nodeValue;
} 
Jannie Theunissen
  • 28,256
  • 21
  • 100
  • 127
  • This does not adequately I want to do is drag history and also code video Such as **44lxceMeFT8 AND 13 Nov 2011 12:29:18 +0000** – 10neen com Nov 15 '11 at 23:20
  • @10neencom this is just a sample to get you going in the right direction. This is a place to learn, not have the community write your whole application for you. – Jannie Theunissen Nov 16 '11 at 09:58
1

Use a DOM parser and then a regex parser in individual elements in the DOM (using things like getElementById()). It works better and is more failsafe.

brunoais
  • 6,258
  • 8
  • 39
  • 59