Jump to content

word wrap is giving error while validating page


$php_mysql$

Recommended Posts

got this function in php.net i guess

 

function mywordwrap($string)
{
$length = strlen($string);

for ($i=0; $i<=$length; $i=$i+1)
    {
    $char = substr($string, $i, 1);
    if ($char == "<")
        $skip=1;
    elseif ($char == ">")
        $skip=0;
    elseif ($char == " ")
        $wrap=0;

    if ($skip==0)
        $wrap=$wrap+1;

    $returnvar = $returnvar . $char;

    if ($wrap> // alter this number to set the maximum word length
        {
        $returnvar = $returnvar . "<wbr>";
        $wrap=0;
        }
    }

return $returnvar;

} 

 

after using this when i try to validate my page in http://validator.w3.org i get this error

 

Line 124, Column 38: end tag for "wbr" omitted, but OMITTAG NO was specified

  <td width="15%">sdfasdfsdfadfddfdfsafasd<wbr>a</td>

You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".

 

what is the fix for this?

nl2br will not work for it would make my table go out of the main content. the function above works like i need but bcoz or the <wbr> i get validation error

 

i got a row for title 70 characters max and the with is 50% without wraping the text my table gets messed up :-D

thanks bro found a substitute :-)

 

function mywordwrap1($text,$nr=35) 
    { 
        $mytext=explode(" ",trim($text)); 
        $newtext=array(); 
        foreach($mytext as $k=>$txt) 
        { 
            if (strlen($txt)>$nr) 
            { 
                $txt=wordwrap($txt, $nr, "-", 1); 
            } 
            $newtext[]=$txt; 
        } 
        return implode(" ",$newtext); 
    } 

tho it puts a - it would have been nice if it didn but it does the work :-) thanks soo much.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.