Advertisement
MizunoBrasil

Pega Title (html e php)

Mar 8th, 2023 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. <form method="POST" action="">
  2.     <label for="url-input">Insira uma URL:</label>
  3.     <input type="text" id="url-input" name="url">
  4.     <button type="submit" name="submit">Obter título</button>
  5. </form>
  6.  
  7. <p id="title">
  8.     <?php
  9.         if (isset($_POST['submit'])) {
  10.             $url = $_POST['url'];
  11.             $html = file_get_contents($url);
  12.             $title = preg_match('/<title>(.*)<\/title>/', $html, $matches);
  13.             echo $matches[1];
  14.         }
  15.     ?>
  16. </p>
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement