2017 © Pedro Peláez
 

library text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

image

hegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  • Monday, May 8, 2017
  • by rogerhegland
  • Repository
  • 1 Watchers
  • 0 Stars
  • 479 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 8 % Grown

The README.md

text-parser

It allows you to cut the needed part of a text in given text, (*1)

examples

Find one

<div class="id1">
    <table>
        <thead>
            <tr>
                <th>company</th>
                <th>urls</th>
                <th>zipcode & city</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Hegland GmbH</td>
                <td>
                    <ul>
                        <li>http://www.companylink1.ch</li>
                        <li>http://www.companylink2.ch</li>
                        <li>http://www.companylink3.ch</li>
                    </ul>
                </td>
                <td>8400 Winterthur</td>
            </tr>
        </tbody>        
    </table>
</div>
<ul>
<li>http://www.link1.ch</li>
<li>http://www.link2.ch</li>
<li>http://www.link3.ch</li>
</ul>
<div class="id2">
           ^^^^^^
    <table>
        <thead>
            <tr>
                <th>name</th>
                <th>street</th>
                <th>zipcode & city</th>
            </tr>
        </thead>
        <tbody>
        ^^^^^^^
            <tr>
                <td>Roger Hegland</td>
                ^^^^=============^^^^^
                <td>Châtelstrasse 13</td>
                <td>8355 Aadorf</td>
            </tr>
        </tbody>        
    </table>
</div>

In the following example we get the name "Roger Hegland":, (*2)

$name = Parser::findOne($text, '"id2">', '<tbody>', '<td>', '</td>');

/*
result = (string) 'Roger Hegland'
*/

Find many

Please notice, that the first parameter is used for the end search., (*3)

In the following example we get all link names:, (*4)

<div class="id1">
    <table>
        <thead>
            <tr>
                <th>company</th>
                <th>urls</th>
                <th>zipcode & city</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Hegland GmbH</td>
                <td>
                    <ul>
                        <li><a href="http://www.companylink1.ch">companylink1</a></li>
                        ^^^^                                   ^^============^^^^
                        <li><a href="http://www.companylink2.ch">companylink2</a></li>
                        ^^^^                                   ^^============^^^^
                        <li><a href="http://www.companylink3.ch">companylink3</a></li>
                        ^^^^                                   ^^============^^^^
                    </ul>
                </td>
                <td>8400 Winterthur</td>
            </tr>
        </tbody>        
    </table>
</div>
<ul>
<li><a href="http://www.link1.ch">link1</a></li>
^^^^                            ^^=====^^^^
<li><a href="http://www.link2.ch">link2</a></li>
^^^^                            ^^=====^^^^
<li><a href="http://www.link3.ch">link3</a></li>
^^^^                            ^^=====^^^^
</ul>
<div class="id2">
    <table>
        <thead>
            <tr>
                <th>name</th>
                <th>street</th>
                <th>zipcode & city</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Roger Hegland</td>
                <td>Châtelstrasse 13</td>
                <td>8355 Aadorf</td>
            </tr>
        </tbody>        
    </table>
</div>
Parser::findMany($text, '</a>', '<li>', '">' );

/*
result = array
[
    'companylink1',
    'companylink2',
    'companylink3',
    'link1',
    'link2',
    'link3'
]
*/

If you only need the link names in the table you can do something like this:, (*5)

<div class="id1">
    <table>
        <thead>
            <tr>
                <th>company</th>
                <th>urls</th>
                <th>zipcode & city</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Hegland GmbH</td>
                <td>
                    <ul>
                        <li><a href="http://www.companylink1.ch">companylink1</a></li>
                        ^^^^                                   ^^============^^^^
                        <li><a href="http://www.companylink2.ch">companylink2</a></li>
                        ^^^^                                   ^^============^^^^
                        <li><a href="http://www.companylink3.ch">companylink3</a></li>
                        ^^^^                                   ^^============^^^^
                    </ul>
                </td>
                <td>8400 Winterthur</td>
            </tr>
        </tbody>
    </table>
</div>
<ul>
<li><a href="http://www.link1.ch">link1</a></li>
<li><a href="http://www.link2.ch">link2</a></li>
<li><a href="http://www.link3.ch">link3</a></li>
</ul>
<div class="id2">
    <table>
        <thead>
            <tr>
                <th>name</th>
                <th>street</th>
                <th>zipcode & city</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>Roger Hegland</td>
                <td>Châtelstrasse 13</td>
                <td>8355 Aadorf</td>
            </tr>
        </tbody>        
    </table>
</div>
$text = Parser::findOne($text, '<tbody>', '</tbody>' );
Parser::findMany($text, '</a>', '<li>', '">' );

/*
result = array
[
    'companylink1',
    'companylink2',
    'companylink3',
]
*/

The Versions

08/05 2017

dev-master

9999999-dev https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=7.0

 

The Development Requires

by Roger Hegland

parser

08/05 2017

2.0.0

2.0.0.0 https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=7.0

 

The Development Requires

by Roger Hegland

parser

22/02 2017

1.0.6

1.0.6.0 https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=7.0

 

The Development Requires

by Roger Hegland

parser

21/02 2017

1.0.5

1.0.5.0 https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=7.0

 

The Development Requires

by Roger Hegland

parser

22/07 2016

1.0.4

1.0.4.0 https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=7.0

 

The Development Requires

by Roger Hegland

parser

21/07 2016

1.0.3

1.0.3.0 https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=7.0

 

The Development Requires

by Roger Hegland

parser

06/06 2016

1.0.0

1.0.0.0 https://github.com/rogerhegland/text-parser

A Text parser. It allows you to cut out the needed part of a text from a given text.

  Sources   Download

Apache License 2.0

The Requires

  • php >=5.6

 

The Development Requires

by Roger Hegland

parser