Git Product home page Git Product logo

text-parser's Introduction

text-parser

It allows you to cut the needed part of a text in given text

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":

$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.

In the following example we get all link names:

<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:

<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',
]
*/

text-parser's People

Contributors

rogerhegland avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.