Answer the question
In order to leave comments, you need to log in
How can I extract text from a website?
It is necessary that the generated advice be copied from the site https://randome.pro/sovet.php and inserted into a variable. I would be glad if you write the code in full and describe each element so that I can understand and understand the principle of operation.
Answer the question
In order to leave comments, you need to log in
If you ask for a ready-made code, you won't go anywhere.
I'll sign it step by step:
1. You get the content of the page via cURL.
2. With the help of regular expressions you "tear out" advice from HTML.
3. PROFIT!!!
$html = file_get_contents('http://randome.pro/sovet.php'); /* получем код страницы в переменную $html */
preg_match('/<span style="font-size: 40px;">(.*?)<\/span>/is', $html, $result); /* получаем содержимое тэга span в массив $result с помощью регулярного выражения */
$str = trim($result[1]); /* присваиваем нужный нам текст переменной $str убирая лишние пробелы функцией trim */
print_r($str); /* выводим наш текст */
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question