Hello. There is the following code:

$ch = curl_init('http://example.com/'); curl_setopt($ch, CURLOPT_USERAGENT, 'S'); curl_exec($ch); curl_close($ch); 

How to choose, for example, a div with the class 'name', who knows? It is desirable, without using libraries, or with phpQuery. Well, if there is no other way, then let's go with the libraries. I would be grateful for the help!

I tried using phpQuery to do this, but it did not work:

 require 'phpQuery.php'; $text = curl_exec($ch); phpQuery::newDocument($text); $new_text = pq('.name'); echo $new_text; phpQuery::unloadDocuments(); 
  • Is phpQuery not a library? Where are your attempts to do this? - teran
  • @teran, my attempts are vain. sense their spread and confuse people? - rebber
  • there two lines of code are needed for this purpose (in phpQuery). one to create a document, the second to select div. - teran
  • @teran, updated the question. - rebber
  • one
    What about SimpleHTMLDom? - NTP

1 answer 1

A variant with the use of regular expressions, but if you need to look for several entries by different parameters, then perhaps you will be more comfortable using the appropriate library for this purpose.

 <?php $url = 'fl.ru/tu/53279/perenos-sayta-s-joomla-na-wordpress.html'; preg_match_all('~<h1[^>]*>([\w\s]+)</h1>~iu', curl($url), $arr); echo $arr[1][0]; // Перенос сайта с joomla на wordpress function curl($url) { $ua = strip_tags($_SERVER['HTTP_USER_AGENT']); $ch = curl_init(); $options = [ CURLOPT_URL => $url, CURLOPT_USERAGENT => $ua, CURLOPT_TIMEOUT => 10, CURLOPT_RETURNTRANSFER => 1, CURLOPT_FOLLOWLOCATION => 1 ]; curl_setopt_array($ch, $options); $result = curl_exec($ch); curl_close($ch); return $result; }