doukun8944 2013-07-23 11:05
浏览 6

从HTML获取特定输出

<div class="info">
    <ul class="links">
    </ul>
    <h1>Vykúpenie z väznice Shawshank</h1>
    <ul class="names">
       <li>
       <img src="http://img.csfd.cz/assets/images/flags/flag_1.gif" alt="USA"  />
       <h3>Shawshank Redemption, The</h3>
       </li>
       <li>
       <img src="http://img.csfd.cz/assets/images/flags/flag_34.gif" alt="CZ název"  />
       <h3>Vykoupení z věznice Shawshank</h3>
       </li>
    </ul>

Hey guys, this is part of big HTML, what i need is to use HTML SIMPLE DOM PRASER and get this 3 text : "Vyykúpenie z väznice Shawshank", "Shawshank Redemption, The", "Vykoupení z věznice Shawshank" How should i do that?

my try of PHP code:

$html = file_get_html('file.txt'); 
$ret = $html->find('ul[class="links"]');   //nazov filmu


foreach ($ret as $translate) {
    $translate = $translate->innertext;
    }   
    echo "$translate";      
  • 写回答

2条回答 默认 最新

  • doulao3905 2013-07-23 11:12
    关注

    There are so many ways to do the translation. You can use contants you can use method. The one of my favourite way is to use Zend Translate check it.

    The main aim is to create method which will change some contants depending on language.

     class Translator
     {
        public static $lang = 'en';
        public function translate($str){
           if(isset($this->data[$str]))
           return $this->data[$str];
           else return 'no translation';
        }
     }
    
     $translate->('DO_HOMEWORK'); 
    

    Language should be stored in session and depends on language it should give proper values. You can get $this->data from CSV files, ini files or get it straightly from the array it doesn't really mater. You can use singleton pattern to Translator class.

    评论

报告相同问题?

悬赏问题

  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”