Jump to content

Recommended Posts

How can I post on wordpress with this script and how can I edit the post if images from the original page have been changed?

 

<?php // File: MatchAllDivMain.php

// Read html file to be processed into $data variable
$data = file_get_contents('test.html');

// Commented regex to extract contents from <div class="main">contents</div>
//  where "contents" may contain nested <div>s.
//  Regex uses PCRE's recursive (?1) sub expression syntax to recurs group 1
$pattern_long = '{		   # recursive regex to capture contents of "main" DIV
<div\s+class="main"\s*>			  # match the "main" class DIV opening tag
 (								   # capture "main" DIV contents into $1
   (?:							   # non-cap group for nesting * quantifier
  (?: (?!<div[^>]*>|</div>). )++  # possessively match all non-DIV tag chars
   |								 # or
  <div[^>]*>(?1)</div>		    # recursively match nested <div>xyz</div>
   )*							    # loop however deep as necessary
 )								   # end group 1 capture
</div>							   # match the "main" class DIV closing tag
}six';  // single-line (dot matches all), ignore case and free spacing modes ON

// short version of same regex
$pattern_short = '{<div\s+class="main"\s*>((??:(?!<div[^>]*>|</div>).)++|<div[^>]*>(?1)</div>)*)</div>}si';

$matchcount = preg_match_all($pattern_long, $data, $matches);
// $matchcount = preg_match_all($pattern_short, $data, $matches);
echo("<pre>\n");
if ($matchcount > 0) {
   echo("$matchcount matches found.\n");
//  print_r($matches);
   for($i = 0; $i < $matchcount; $i++) {
    echo("\nMatch #" . ($i + 1) . ":\n");
    echo($matches[1][$i]); // print 1st capture group for match number i
   }
} else {
   echo('No matches');
}
echo("\n</pre>");
?>

Link to comment
https://forums.phpfreaks.com/topic/272140-wordpress-php-post/
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.