Jump to content

[SOLVED] help with php and regex


CodeMama

Recommended Posts

trying to clean out all tags except the <br> on some data so I can put it in a database

 

How can I write this:

<?php


$TESTING = TRUE;


$target_url = "http://www.awebsite.com";

$userAgent = 'Googlebot/2.1 (http://www.googlebot.com/bot.html)';


$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
$html = curl_exec($ch);
if (!$html) {
    echo "<br />cURL error number:" .curl_errno($ch);
    echo "<br />cURL error:" . curl_error($ch);
    exit;
}


// parse the html into a DOMDocument
$dom = new DOMDocument();
@$dom->loadHTML($html);

echo $html;

$graphs = split("<p", $html);

// Start at 6 to clear out junk at top. Use $i+1 since last paragraph
//        is footnote that is not needed.
for ($i = 6; $i+1 < count($graphs); $i++)
{
        
        
        if($TESTING)
                echo "$i: $graphs[$i]<br />"; 
                
    //split the paragraphs into lines
           
           $graphs->getAttribute('graphs');           $clean = $graphs(\<)(?!br(\s|\/|\>))(.*?\>);           $lines = split("<br", $graphs);                
                //for ($i = 1; $i+1 < count($lines); $i++)
                {
    // Grab restaurant name
                if($TESTING)
                echo "$i: $lines[$i]<br />"; 
                }
    // Grab address
    
    // Grab city
    
    
    // Grab date and visit type
    
    
    // Grab rest of text and store it. Grab numbers of violations?
    

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.