i want to receive text from html ,i received html page and i want to extract from this page text file how can i change this code: <?php $page = file_get_contents(' website'); $fh=fopen("file1.txt","a"); fwrite($fh,$page); fclose($fh); ?> Code (markup):
Also, if you cast a slight glance upwards when you enter "programming" in the forum list, you'll see there's a "php" - forum, for (gasp!) php related questions
i have this html code: <h4 class="h4bit"><a href="https://www.seoclerk.com/Social-Networks/10394/promote-any-url-on-30-Million-FB-groups-OR-99-PR-9-Search-Engine-Indexing" class="listbit">promote any <span>url</span> on 30 Million FB groups OR, 99 PR 9 Sear... for $10</a></h4> i need to receive text:https://www.seoclerk.com/Social-Networks/10394/promote-any-url-on-30-Million-FB-groups-OR-99-PR-9-Search-Engine-Indexing i need to filter html tags this my question
I think this function can help you <?php function getArray($node) { $array = false; if ($node->hasAttributes()) { foreach ($node->attributes as $attr) { $array[$attr->nodeName] = $attr->nodeValue; } } if ($node->hasChildNodes()) { if ($node->childNodes->length == 1) { $array[$node->firstChild->nodeName] = $node->firstChild->nodeValue; } else { foreach ($node->childNodes as $childNode) { if ($childNode->nodeType != XML_TEXT_NODE) { $array[$childNode->nodeName][] = $this->getArray($childNode); } } } } return $array; } ?> PHP:
While DOM can be the answer, simple scraping can be done with preg_match: //I assume you need the class.. $pattern = "/<a href=\"(.*)\" class=\"listbit\">/siU" preg_match_all($pattern,$string,$results); print_r($results[1]); PHP: