Jump to content

Need help with string


soggy

Recommended Posts

I am kinda new to php and need this string described to me

([^`]*?)


I am trying to get this to load the title and link

[code]

<?php

// Screen scraping your way into RSS
// Example script, by Dennis Pallett
// http://www.phpit.net/tutorials/screenscrap-rss

// Get page
$url = "http://titansradio.com";
$data = implode("", file($url));

// Get content items
preg_match_all ("/<A HREF\=cgi-bin([^`]*?)\br/", $data, $matches);

// Begin feed
header ("Content-Type: text/xml; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
?>
<rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:admin="http://webns.net/mvcb/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <channel>
        <title>Titans Radio</title>
        <description>The latest news from titansradio.com</description>
        <link>http://titansradio.com</link>
        <language>en-us</language>


<?
// Loop through each content item
foreach ($matches[0] as $match) {
    // First, get title
    preg_match ("/>\([^`]*?)<\/a/", $match, $temp);
    $title = $temp['1'];
    $title = strip_tags($title);
    $title = trim($title);

    // Second, get url
    preg_match ("/blurb_view\.cgi([^`]*?)>\/", $match, $temp);
    $url = $temp['1'];
    $url = trim($url);

    // Third, get text
    preg_match ("/<p>([^`]*?)<span class=\"byline\">/", $match, $temp);
    $text = $temp['1'];
    $text = trim($text);

    // Fourth, and finally, get author
    preg_match ("/<span class=\"byline\">By ([^`]*?)<\/span>/", $match, $temp);
    $author = $temp['1'];
    $author = trim($author);

    // Echo RSS XML
    echo "<item>\n";
        echo "\t\t\t<title>" . strip_tags($title) . "</title>\n";
        echo "\t\t\t<link>" . strip_tags($url) . "</link>\n";
        echo "\t\t\t<description>" . strip_tags($text) . "</description>\n";
        echo "\t\t\t<content:encoded><![CDATA[ \n";
        echo $text . "\n";
        echo " ]]></content:encoded>\n";
        echo "\t\t\t<dc:creator>" . strip_tags($author) . "</dc:creator>\n";
    echo "\t\t</item>\n";
}
?>
</channel>
</rss> [/code]
Link to comment
Share on other sites

[!--quoteo(post=370018:date=Apr 29 2006, 10:48 PM:name=soggy)--][div class=\'quotetop\']QUOTE(soggy @ Apr 29 2006, 10:48 PM) [snapback]370018[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I am kinda new to php and need this string described to me

([^`]*?)
I am trying to get this to load the title and link

[code]

<?php

// Screen scraping your way into RSS
// Example script, by Dennis Pallett
// http://www.phpit.net/tutorials/screenscrap-rss

// Get page
$url = "http://titansradio.com";
$data = implode("", file($url));

// Get content items
preg_match_all ("/<A HREF\=cgi-bin([^`]*?)\br/", $data, $matches);

// Begin feed
header ("Content-Type: text/xml; charset=ISO-8859-1");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
?>
<rss version="2.0"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:admin="http://webns.net/mvcb/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <channel>
        <title>Titans Radio</title>
        <description>The latest news from titansradio.com</description>
        <link>http://titansradio.com</link>
        <language>en-us</language>
<?
// Loop through each content item
foreach ($matches[0] as $match) {
    // First, get title
    preg_match ("/>\([^`]*?)<\/a/", $match, $temp);
    $title = $temp['1'];
    $title = strip_tags($title);
    $title = trim($title);

    // Second, get url
    preg_match ("/blurb_view\.cgi([^`]*?)>\/", $match, $temp);
    $url = $temp['1'];
    $url = trim($url);

    // Third, get text
    preg_match ("/<p>([^`]*?)<span class=\"byline\">/", $match, $temp);
    $text = $temp['1'];
    $text = trim($text);

    // Fourth, and finally, get author
    preg_match ("/<span class=\"byline\">By ([^`]*?)<\/span>/", $match, $temp);
    $author = $temp['1'];
    $author = trim($author);

    // Echo RSS XML
    echo "<item>\n";
        echo "\t\t\t<title>" . strip_tags($title) . "</title>\n";
        echo "\t\t\t<link>" . strip_tags($url) . "</link>\n";
        echo "\t\t\t<description>" . strip_tags($text) . "</description>\n";
        echo "\t\t\t<content:encoded><![CDATA[ \n";
        echo $text . "\n";
        echo " ]]></content:encoded>\n";
        echo "\t\t\t<dc:creator>" . strip_tags($author) . "</dc:creator>\n";
    echo "\t\t</item>\n";
}
?>
</channel>
</rss> [/code]
[/quote]

Your help request isn't very clear (to me) but the "string" that you asked about looks like an excerpt from a regex statement?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.