Note that there are some explanatory texts on larger screens.

plurals
  1. POExtracting sub string from web page content
    primarykey
    data
    text
    <p>I am parsing web page data using <code>file_get_content</code>. Now I want to extact first 150 character as a description for that url.</p> <pre><code> $url = 'http://crewow.com/CSS_Layout_Tutorial.php'; $data = file_get_contents($url); $content = plaintext($data); $Preview = trim_display(140,$content); //to Show first 100 char of the web page as preview echo $Preview; function trim_display($size,$string) { echo "string is : $string &lt;br/&gt;"; $trim_string = substr($string, 0, 150); $trim_string = $trim_string . "..."; echo "Trim string is $trim_string &lt;br/&gt;"; return $trim_string; } function plaintext($html) { $plaintext = preg_replace('#([&lt;]title)(.*)([&lt;]/title[&gt;])#s', ' ', $html); // remove title //$plaintext = preg_match('#&lt;title&gt;(.*?)&lt;/title&gt;#', $html); // remove comments and any content found in the the comment area (strip_tags only removes the actual tags). $plaintext = preg_replace('#&lt;!--.*?--&gt;#s', '', $plaintext); // put a space between list items (strip_tags just removes the tags). $plaintext = preg_replace('#&lt;/li&gt;#', ' &lt;/li&gt;', $plaintext); // remove all script and style tags $plaintext = preg_replace('#&lt;(script|style)\b[^&gt;]*&gt;(.*?)&lt;/(script|style)&gt;#is', "", $plaintext); // remove br tags (missed by strip_tags) // remove all remaining html $plaintext = strip_tags($plaintext); return $plaintext; } </code></pre> <p>This code works well for some url. For few it does not show any thing in $Preview. Data sent to <code>trim_display()</code> correctly but fails <code>$trim_string = substr($string, 0, 150);</code>. </p> <p>Output of this remail empty.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload