使用php&#39的数组获取实际文本

时间:2011-01-27 22:23:58

标签: php arrays

我为您创建了一个演示页面。 Demo

Php来源:

<?php
$hoppa = array
(
    "0" => array
        ("0","0","0","0","0","0","0","0","0","0"),
    "1" => array
        ("0","0","0","0","0","0","0","0","0","0"),      
    "2" => array
        ("1","0","0","1","0","0","0","0","0","0"),
    "3" => array
        ("1","0","0","1","0","1","1","1","1","0"),
    "4" => array
        ("1","1","1","1","0","0","0","0","1","0"),
    "5" => array
        ("1","0","0","1","0","1","1","1","1","0"),
    "6" => array
        ("1","0","0","1","0","1","0","0","1","0"),
    "7" => array
        ("1","0","0","1","0","1","1","1","1","0"),
    "8" => array
        ("0","0","0","0","0","0","0","0","0","0"),
    "9" => array
        ("0","0","0","0","0","0","0","0","0","0")                                   

);
function showmee($hoppa) {
echo '<table width="500px" cellpadding="4" cellspacing="4" border="5" bordercolor="#ededed">';
echo '<tr>
<td align="center" style="border:1px solid blue">-</td>
<td align="center" style="border:1px solid blue">x1</td>
<td align="center" style="border:1px solid blue">x2</td>
<td align="center" style="border:1px solid blue">x3</td>
<td align="center" style="border:1px solid blue">x4</td>
<td align="center" style="border:1px solid blue">x5</td>
<td align="center" style="border:1px solid blue">x6</td>
<td align="center" style="border:1px solid blue">x7</td>
<td align="center" style="border:1px solid blue">x8</td>
<td align="center" style="border:1px solid blue">x9</td>
<td align="center" style="border:1px solid blue">x10</td>
</tr>';
$count = 1; 
 foreach($hoppa as $h=>$g) {
     echo '<tr>';
     echo '<td align="center" style="border:1px solid blue">y'.$count++.'</td>';
     foreach($hoppa[$h] as $p) {
         if($p==1){      
         echo '<td align="center" style="border:1px solid blue; background-color:orange; color:#FFFFFF">1</td>';
         }
         else{ 
         echo '<td align="center" style="border:1px solid blue">0</td>';
         }
         } 
     echo '</tr>';


     }

    echo '</table>';
    }
?>
<title>Test page for stackoverflow.com</title>
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="margin-bottom:15px;">
<tr>
<td style="border-bottom:1px solid #66CC00;padding-bottom:7px;"><b>Hi, this is Taffarel from stackoverflow.com.</b><br />
My problem: I'd like to read(or get) actual text by using PHP.
</td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="1">
<!-- Codes are begining from here -->
<?php showmee($hoppa); ?>
<!-- Codes are ending here -->
</td>
<td align="left" style="padding-left:20px;" valign="top">
<table>
<tr>
<td>
Php array output ( 0 = white , 1 = red):
</td>
</tr>
<tr>
<td>
<textarea rows="20" name="S1" cols="61">
<?php print_r($hoppa); ?>
</textarea>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" width="500px" style="margin-top:15px;border-top:1px solid #0066FF"><tr><td style="padding-top:5px;">How can i echo "Ha" as text by using PHP?</td></tr></table>

Php数组输出(0 =白色,1 =红色):

Array
(
    [0] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
        )

    [1] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
        )

    [2] => Array
        (
            [0] => 1
            [1] => 0
            [2] => 0
            [3] => 1
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
        )

    [3] => Array
        (
            [0] => 1
            [1] => 0
            [2] => 0
            [3] => 1
            [4] => 0
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => 1
            [9] => 0
        )

    [4] => Array
        (
            [0] => 1
            [1] => 1
            [2] => 1
            [3] => 1
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 1
            [9] => 0
        )

    [5] => Array
        (
            [0] => 1
            [1] => 0
            [2] => 0
            [3] => 1
            [4] => 0
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => 1
            [9] => 0
        )

    [6] => Array
        (
            [0] => 1
            [1] => 0
            [2] => 0
            [3] => 1
            [4] => 0
            [5] => 1
            [6] => 0
            [7] => 0
            [8] => 1
            [9] => 0
        )

    [7] => Array
        (
            [0] => 1
            [1] => 0
            [2] => 0
            [3] => 1
            [4] => 0
            [5] => 1
            [6] => 1
            [7] => 1
            [8] => 1
            [9] => 0
        )

    [8] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
        )

    [9] => Array
        (
            [0] => 0
            [1] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [7] => 0
            [8] => 0
            [9] => 0
        )

)

我想通过PHP阅读(或获取)实际文本。如何使用PHP将“Ha”作为文本回显?

2 个答案:

答案 0 :(得分:0)

您可能需要为可能打印的每个字符执行某种映射。然后你必须遍历数组,看看你是否有匹配。假设一个全0数组是一个信号,继续下一个字母。 这似乎非常麻烦,而且非常费时。

您的总体目标是什么?也许有更好的方法来处理整个事情。

答案 1 :(得分:0)

如果您正在尝试进行光学字符识别,那么最好使用某些库,phpOCR。如果您对算法感兴趣,那么只需阅读其中一个库的源代码。不要认为可以用简短的答案来解释。