Php function to encode tabs etc to html

I'm looking for a function that encodes spaces, tabs etc into html characters

Eg take the collection of strings:

        Whats up?&^5@#
number  pie     word
1       3       hi
2       4       no

which I process:

$outString="";
for($i=0;$i<count($strArr);$i++){
    $outString.= somefunc($strArr[$i]);//what should somefunc be?
 }

Answers


have you seen html entities or html special chars ?


HTML doesn't have any means of representing a tab stop, so this isn't achievable per se.

You could wrap the content in a <pre> element, but this would be better addressed by explodeing each line on tab characters, and then generating a <table> from the resulting data structure.


You won't be able to create tabs in html, but if you change all to html table, you should be ok. Try something like this:

function foo($string) {
    $table='<table border="0">'.htmlentities($string).'</table>';
    $table=preg_replace( "#\r\n#", "</td></tr><tr><td>", $table);
    $table=preg_replace( "#\t#", "</td><td>", $table);

    return $table;
}

Need Your Help

Best design to avoid "local variable as default parameter"?

c++ default-parameters

I'm writing an approximation function taking two different tolerance values as parameters:

How do i get out of the habit of procedural programming and into object oriented programming?

php oop procedural-programming

I'm hoping to get some tips to kinda help me break out of what i consider after all these years a bad habit of procedural programming. Every time i attempt to do a project in OOP i end up eventually