I
I
Ilya2018-10-13 22:53:13
PHP
Ilya, 2018-10-13 22:53:13

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

2 answer(s)
M
Maxim, 2018-10-13
Alexsev @MaxGoody

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!!!

D
DanKud, 2018-10-13
@DanKud

$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 question

Ask a Question

731 491 924 answers to any question