PHP - jak získat řetězec mezi dvěma znaky (regex, regulární výraz)

Autor Aschenbrenner
Publikováno 16.09.2020
Kategorie programovani
Stav Vyřešeno
Dobrý den,

potřeboval bych pomocí php regex (regulárního výrazu) vypreparovat z rětězce níže tento string = "77x6v11133-xjrdg"


HTTP/2 201 server: nginx/1.14.2 content-type: application/json; charset=UTF-8 set-cookie: PHPSESSID=1cp5phpdb0n8qcbn3n5v1mesau; path=/; secure; HttpOnly cache-control: max-age=0, must-revalidate, private date: Tue, 25 Aug 2020 10:38:59 GMT x-csrf-token: oNBYCwWF9YdSLHLN8eTkoyKuoL3ax-YHHp0o_syTv58 allow: POST, GET link: < /admin/block/77x6v11133-xjrdg>; rel="resource" expires: Tue, 25 Aug 2020 10:38:59 GMT


Odpovědi na dotaz 3

The English language is translated by machine - the translator can modify eg cited codes = it is better to use codes from the Czech original.

PHP - regex between two characters

Hi,

I would need to use php regex to prepare this string from the string below = "77x6v11133-xjrdg"


HTTP/2 201 server: nginx/1.14.2 content-type: application/json; charset=UTF-8 set-cookie: PHPSESSID=1cp5phpdb0n8qcbn3n5v1mesau; path=/; secure; HttpOnly cache-control: max-age=0, must-revalidate, private date: Tue, 25 Aug 2020 10:38:59 GMT x-csrf-token: oNBYCwWF9YdSLHLN8eTkoyKuoL3ax-YHHp0o_syTv58 allow: POST, GET link: < /admin/block/77x6v11133-xjrdg>; rel="resource" expires: Tue, 25 Aug 2020 10:38:59 GMT

RE: PHP - jak získat řetězec mezi dvěma znaky (regex,…

Autor Hyacint
Publikováno 23.09.2020
Kategorie programovani
Stav Zkontrolováno
Dobrý den,

nejsem odborní na regulární výrazy, ale když na to půjdete trochu oklikou, tak by to šlo takto:

Udělat php explode do pole dle oddělovače "/admin/block"

a pak regex mezi znakem "/" a ">"


$arr = explode('admin/block', $string);
$matches = array();
$t = preg_match('/\/(.*?)\>/', $arr[1], $matches);
if (isset($matches[1])) {
return $matches[1];
}


Ověřeno, že to funguje...


3

The English language is translated by machine - the translator can modify eg cited codes = it is better to use codes from the Czech original.

PHP - regex between two characters

Hi,

I'm not expert in regular expressions, but if you take a little detour, it would go like this:

Make a php explode into an array according to the "/admin/block" delimiter

and then regex between the "/" and ">" characters


$arr = explode('admin/block', $string);
$matches = array();
$t = preg_match('/\/(.*?)\>/', $arr[1], $matches);
if (isset($matches[1])) {
return $matches[1];
}


It works...
Tento web používá k poskytování služeb, personalizaci reklam a analýze návštěvnosti soubory cookie. Používáním tohoto webu s tím souhlasíte. Další informace