Andurit
Andurit

Reputation: 5762

Get specific output from 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";      

Upvotes: 0

Views: 117

Answers (2)

Ahmad Asjad
Ahmad Asjad

Reputation: 823

I think you want so:

<div class="info">
    <ul class="links">
        <li><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>
        </li>
    </ul>
</div>

Upvotes: 1

Robert
Robert

Reputation: 20286

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.

Upvotes: 1

Related Questions