What are best practices for writing PHP scripts to bookmark information from a webpage?

When writing PHP scripts to bookmark information from a webpage, it is best practice to use a combination of cURL for fetching the webpage content and regular expressions for extracting the desired information. By using cURL, you can retrieve the webpage's HTML content, and then use regular expressions to parse and extract the specific data you want to bookmark.

<?php

// URL of the webpage to bookmark
$url = 'https://www.example.com/page';

// Initialize cURL session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute cURL session and store the webpage content
$html = curl_exec($ch);

// Close cURL session
curl_close($ch);

// Regular expression to extract specific information from the webpage
$pattern = '/<title>(.*?)<\/title>/'; // Example: Extracting the title tag content

// Perform regular expression match
preg_match($pattern, $html, $matches);

// Output the extracted information
echo $matches[1]; // Display the extracted title

?>