Jump to content

Problem when using substr


convinceme

Recommended Posts

function strtrim($str, $maxlen=500, $elli=NULL, $maxoverflow=180) {
    global $CONF;
        
    if (strlen($str) > $maxlen) {
            
        if ($CONF["BODY_TRIM_METHOD_STRLEN"]) {
            return substr($str, 0, $maxlen);
        }
            
        $output = NULL;
        $body = explode(" ", $str);
        $body_count = count($body);
        
        $i=0;
    
        do {
            $output .= $body[$i]." ";
            $thisLen = strlen($output);
            $cycle = ($thisLen < $maxlen && $i < $body_count-1 && ($thisLen+strlen($body[$i+1])) < $maxlen+$maxoverflow?true:false);

            $i++;
        } while ($cycle);
        return $output.$elli."...";
    }
    else return $str.$elli;
}

When i use the above chunk of code i end up getting the following value being displayed

Karachi: The Meteorological Department on Monday warned of more heavy rains in Sindh and Baluchistan as a possible cyclone headed for Pakistan’s coastal areas.

 

<SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: ...

Now how to get rid of this "<span style" part... I want it to just display the text apart from these tags.

The data in the mysql database for which the output being generated is

 

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">Karachi: The Meteorological Department on Monday warned of more heavy rains in Sindh and Baluchistan as a possible cyclone headed for Pakistan’s coastal areas.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></SPAN></P>

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">The department issued an alert at 2:00pm on Monday warning that a tropical storm forming in the Arabian Sea, 150 kilometers south of Karachi, was likely to intensify into a cyclone within the next 12 hours. The associated storm surge is expected to be 10-15 feet along the Sindh coast and 20-25 feet along Baluchistan’s coastline. Met office officials said the cyclone would not directly strike Karachi.<o:p></o:p></SPAN></P>

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">The Met Department forecast gusty winds of between 40-50 and 60-70 knots with scattered “heavy to very heavy” rainfall in Sindh, especially in southern Sindh and coastal areas. The cyclone also threatened the Baluchistan coastal areas of Gwadar, Jiwani, Pasni, Ormara and Lasbela.<o:p></o:p></SPAN></P>

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">The met office added that hilly areas, especially in southern Baluchistan, might experience flash floods. Officials in Baluchistan said around 2,000 people had been evacuated to higher ground from areas along the Arabian Sea coast that were already inundated by rain.<o:p></o:p></SPAN></P>

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">Fishermen were advised to stay ashore until June 27 in Sindh and June 28 in Baluchistan because of the likelihood of “Extremely” rough seas. At least 10 fishermen have been missing since the weekend, officials said.<o:p></o:p></SPAN></P>

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">The met office said that Punjab, upper parts of NWFP and Kashmir were also likely to receive rain with thunderstorm and lightning during next 24 hours. It said this season’s monsoon was likely to bring more than normal rains in eastern Sindh, Baluchistan, north and eastern Punjab.<o:p></o:p></SPAN></P>

<P class=MsoNormal style="MARGIN: 0in 0in 10pt"><SPAN style="FONT-SIZE: 9pt; COLOR: black; LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'">Karachi is still reeling from a deadly thunderstorm that killed close to 230 people on Saturday, with parts of the city still without electricity or drinking water.<o:p></o:p></SPAN></P>

 

There are so many tags because i wrote it in Microsoft Word 2007 and pasted it in the the textbox which has richedit enabled (wysiwyg script).

 

Can someone please tell me an easy way to get rid of that "<span" part, as you might see the tags in the starting of the data aren't displayed!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.