PHPackages                             laravieira/scraping - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. laravieira/scraping

ActiveLibrary

laravieira/scraping
===================

Simple Web Scraping Framework, based on Curl and str\* functions.

018PHP

Since Aug 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/laravieira/Scraping)[ Packagist](https://packagist.org/packages/laravieira/scraping)[ RSS](/packages/laravieira-scraping/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Scrapping
=========

[](#scrapping)

Simple Web Scraping Framework, based on Curl and str\* functions. Requires PHP ^8.0 (can easily be downgraded to PHP 7)

What you can do?
================

[](#what-you-can-do)

There is some functions to simplify your script, they are listed below:

### Global functions

[](#global-functions)

- [upname](#upname) =&gt; Format and return string to name formats (first each word character is uppercase)
- [price](#price) =&gt; Return float value of and price string of type 'xx$: 9.999,99'
- [accents](#accents) =&gt; Replace accentuation with equivalent characters
- [strmstr](#strmstr) =&gt; Return string after start3, after start2, after start1
- [strpart](#strpart) =&gt; Return middle string between start and end strings
- [strmpart](#strmpart) =&gt; Return middle string between start2 and end string, which start2 is after start1

### Scrapping object

[](#scrapping-object)

- [Scrapping::cache](#scrapping-cache) =&gt; can save or return an cache
- [Scrapping::cacheFolder](#scrapping-cahefolder) =&gt; you can set a custom folder to cache
- [Scrapping::json](#scrapping-json) =&gt; parse and print the response in json
- [Scrapping::isOnSession](#scrapping-inonsession) =&gt; tell if an session is set with server
- [Scrapping::load](#scrapping-load) =&gt; Reuse session of previews connections
- [Scrapping::useSession](#scrapping-usesession) =&gt; Set/Return if session setting is enabled
- [Scrapping::userAgent](#scrapping-useragent) =&gt; Set/Return userAgent
- [Scrapping::server](#scrapping-server) =&gt; Set/Return server host base URL
- [Scrapping::session](#scrapping-session) =&gt; Set/Return server session id
- [Scrapping::hasSession](#scrapping-hassession) =&gt; Returns if has a server session id set
- [Scrapping::sesionName](#scrapping-sessionname) =&gt; Set/Retrun server session cookie name
- [Scrapping::get](#scrapping-get) =&gt; Make and return an get request to the server
- [Scrapping::post](#scrapping-post) =&gt; Make and return an post request to the server
- [Scrapping::proccess](#scrapping-proccess) =&gt; Proccess the get and post request to organaze data

How to use?
===========

[](#how-to-use)

upname
------

[](#upname)

```
upname(string $text);
```

Just pass the `text` string to format as parameter and the result will be the formated string. Some exemples bellow, the comment of each block represents the output:

#### Examples:

[](#examples)

```
echo upname('lara vieira');
// 'Lara Vieira'
```

```
echo upname('LARA VIEIRA');
// 'Lara Vieira'
```

```
echo upname('LEONARDO DE CÁPRIO');
// 'Leonardo de Cáprio'
```

```
echo upname('DON PEDRO II');
// 'Don Pedro II'
```

price
-----

[](#price)

```
price(string $text);
```

Just pass the `text` string to format as parameter and the result will be the float value. Some exemples bellow, the comment of each block represents the output:

```
echo price('US$: 3.567,56');
// 3567.56
```

```
echo price('R$: 3.456.234,45');
// 3456234.45
```

```
echo price('Price is R$: 234,45');
// 234.45
```

accents
-------

[](#accents)

```
accents(string $text);
```

Just pass the `text` to format as parameter and the result will be the formated string. An exemple bellow, the comment represent the output:

```
echo accents('Aglomeração, Apóstolo, vô, vó');
// 'Aglomeracao, Apostolo, vo, vo'
```

strmstr
-------

[](#strmstr)

```
strmstr(
    string $haystack,
    string $start1,
    string $start2,
    string|null $start3=null
);
```

This function return all `haystack` string after `start3` string that is after `start2` string that is after `start1` string (if `start3` is passed) or all `haystack` string after `start2` string that is after `start1` string. The return will include the last start passed, like [strstr](https://www.php.net/manual/pt_BR/function.strstr.php).

This function is something like an stack of [strstr](https://www.php.net/manual/pt_BR/function.strstr.php) functions:

```
strstr(strstr(strstr(haystack, start1), start2), start3)
```

Some exemples bellow, the comment of each block represents the output:

```
echo strmstr('ABC ABC ABC', 'C');
// 'C ABC ABC'
```

```
echo strmstr('ABC ABC ABC', 'B', 'A');
// 'ABC ABC'
```

```
echo strmstr('ABC ABC ABC', 'B', 'B', 'A');
// 'ABC'
```

strpart
-------

[](#strpart)

*\* This is my favorite one for web-scrapping.*

```
strpart(
    string $haystack,
    string|null $start = null,
    string|null $end = null,
    bool $keep_start = false
);
```

This function will return the middle string in `haystack` between the first occurence of `start` string and the first occurence of `end` string after `start` string.

- If `start` string is null, will return everything in `haystack` before the first occurence of `end` string.
- If `end` string is null, will return everything in `haystack` after the first occurence of `start` string.
- If `keep_start` boolean is set to `true`, default is `false`, the function will return as normal, but including `start` string in the retrun's begin.

Some exemples bellow, the comment of each block represents the output:

```
echo strpart('ABC ABC ABC', ' ', ' ');
// 'ABC'
```

```
echo strpart('ABC ABC ABC', ' ');
// 'ABC ABC'
```

```
echo strpart('ABC ABC ABC', end:' ');
// 'ABC'
```

```
echo strpart('ABC ABC ABC', ' ', ' ', true);
// ' ABC'
```

```
echo strpart('Subtitle', '>', '
