@Jony1337

Как вытащить текст из переменной в php?

Есть
$a = ' <!DOCTYPE html>
<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Raleway:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700' rel='stylesheet' type='text/css'>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="">
<link rel="stylesheet" type="text/css" href="">
<title>NameSite.com</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta property="og:title" content="Appline.ro"/>
<meta property="og:type" content="website"/>
<meta property="og:description" content=""/>
<meta property="og:image" content="" />
<meta property="og:url" content=""/>
<meta property="fb:app_id" content=""/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script> ' ;

Как загнать в переменую $b текста который находится между тэгами title /title
За ранее спасибо если ответили или хотя бы прочитать
  • Вопрос задан
  • 275 просмотров
Решения вопроса 4
gobananas
@gobananas
finishhim.ru
preg_match('/<title>(.*?)<\/title>/ism', $a, $res);

И в $res[1] у вас будет NameSite.com
Ответ написан
Комментировать
usdglander
@usdglander Куратор тега PHP
Yipee-ki-yay
Тут куча примеров надо только немножечко подумать :)
Ответ написан
Комментировать
qork
@qork
{ background: #F00B42 }
$dom = new DOMDocument;
$dom->loadHTML($a);
echo $dom->getElementsByTagName('title')[0]->nodeValue;
Ответ написан
T_y_l_e_r
@T_y_l_e_r
<?php
$a = ' <!DOCTYPE html>
<html>
<head>
<link href=\'http://fonts.googleapis.com/css?family=Raleway:400,700\' rel=\'stylesheet\' type=\'text/css\'>
<link href=\'http://fonts.googleapis.com/css?family=Open+Sans+Condensed:700\' rel=\'stylesheet\' type=\'text/css\'>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
<link rel="stylesheet" type="text/css" href="">
<link rel="stylesheet" type="text/css" href="">
<title>NameSite.com</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta content="width=device-width, initial-scale=1" name="viewport">
<meta property="og:title" content="Appline.ro"/>
<meta property="og:type" content="website"/>
<meta property="og:description" content=""/>
<meta property="og:image" content="" />
<meta property="og:url" content=""/>
<meta property="fb:app_id" content=""/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script> ' ;
preg_match('/title>(.*)<\/title/i', $a, $matches);
$b=$matches[1];
echo $b;
print_r($matches);
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы