PHP search directory load <p> tag from files

66 Views Asked by At

So I need to have a search query done and load any <p> tags in any of the HTML pages and load them under the link to give a short description. so far I got most of the search done but I am having issues with <p> tags loading. my idea was to use "fopen" and then "strip_tags" to pull the <p> tags and then echo them under the link to the HTML document.

so far i have this

$directory = "test/";


if ($submitbutton){
if (!empty($searchoriginal))
{
if (is_dir($directory)){

  if ($open = opendir($directory)){
if ($countsearchterms == 1)
{
    while (($file = readdir($open)) !== false){
    $filecom= $file;
    $file= strtolower($file);
    $file= str_replace("-", " ", $file);
    $file= str_replace("_", " ", $file);
    

 $text = fopen("$file" , "r");

    $position= strpos("$file", ".");
    $file= substr($file, 0, $position);

      if (strpos("$file",  "$search[0]") !== false)
    {        
    $file= ucwords($file);
    $array[] += "$file";
     echo "<a href='http://website here/$directory" . "$filecom'>$file</a>"."<br>";
      echo strip_tags($text, '<p>');
      echo "\n";
}

but after I add "fopen" and echo from "$file" the website will freeze and then crash.

1

There are 1 best solutions below

0
Hunt Computer help On

ok so I was able to figure out.

$St1 = file_get_contents("http://website here/$directory" . "$filecom");
 echo strip_tags($St1, '<p>');

basically it would use the full filename and them get the contents afterwards I would just get the tags from it and then echo on the page.

idk why I did not think of this before but it works.