![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 208 Pomógł: 0 Dołączył: 19.04.2003 Ostrzeżenie: (0%) ![]() ![]() |
Nie wiem czy da się coś takiego zrobić, a jeżeli się da... to jak?
![]() Mam string: Kod attrib1='jakis tekst'"```', attrib2 = "jakis " text'", attrib3 =`'tekst"jakis`, attrib4= '''''' I chciałbym uzyskać taką tablicę:Kod Array Jest to wykonalne?
( [0] => Array ( [0] => attrib1 [1] => attrib2 [2] => attrib3 [3] => attrib4 ) [1] => Array ( [0] => jakis tekst'"``` [1] => jakis " text' [2] => 'tekst"jakis [3] => '''' ) ) |
|
|
![]()
Post
#2
|
|
![]() Grupa: Przyjaciele php.pl Postów: 1 717 Pomógł: 0 Dołączył: 12.06.2002 Skąd: Wolsztyn..... Studia: Zielona Góra Ostrzeżenie: (0%) ![]() ![]() |
Tak. Pomoze w tym napewno preg_match_all.
|
|
|
![]()
Post
#3
|
|
![]() Grupa: Zarejestrowani Postów: 208 Pomógł: 0 Dołączył: 19.04.2003 Ostrzeżenie: (0%) ![]() ![]() |
Wiem, że do tego trzeba użyć funkcji [manual:67b399b540]preg_match_all[/manual:67b399b540], ale nie wiem jakie regularne wyrażenie do niej włożyć
![]() |
|
|
![]()
Post
#4
|
|
![]() Grupa: Zarejestrowani Postów: 115 Pomógł: 0 Dołączył: 3.05.2003 Skąd: Łódź Ostrzeżenie: (0%) ![]() ![]() |
Witam!
moze: '/(atrib[d+]) *= *('[^,]*',|"[^,]*",)/;' ale nie obiecuje ![]() -------------------- pozdrawiam bamboos
http://piorun.ds.pg.gda.pl/~ronek/log/jedyne.wma |
|
|
![]()
Post
#5
|
|
![]() Grupa: Zarejestrowani Postów: 691 Pomógł: 0 Dołączył: 6.08.2003 Ostrzeżenie: (0%) ![]() ![]() |
Cytat Jest to wykonalne?
[php:1:ce22138550]<?php $re = '# *("'`)([^'`"]*(.[^'`"]*)*)1 *,?| *([^,]+) *,?| *,#'; preg_match_all($re, $tekst, $m); $a = array(array(), array()); foreach ($m[4] as $p) list($a[0][], $a[1][]) = preg_split('| *= *|', $p, 2); print_r($a); ?>[/php:1:ce22138550] Ale przetestuj to sobie bo pisałem z głowy. |
|
|
![]()
Post
#6
|
|
![]() Grupa: Zarejestrowani Postów: 208 Pomógł: 0 Dołączył: 19.04.2003 Ostrzeżenie: (0%) ![]() ![]() |
Dobra, mam coś takiego (regExp znalazłem na kochanym php.net
![]() $str = 'attrName="attrV"alue2", attrName=attrValue2, attrName='attr'Value3', atrybut ="w|'''sc" '; $regexp = '/([a-zA-Z0-9]+)( )?=( )?((')|"|)((? ![]() preg_match_all( $regexp, $str, $matches, PREG_SET_ORDER ); print_r( $matches ); ?></pre>[/php:1:40b820874b]I mam taki wynik: Kod Array Tylko, co teraz dodać do tego regExp-a, żebym mógł też używać ` wraz z ' oraz " :?: 8O
( [0] => Array ( [0] => attrName="attrV"alue2", [1] => attrName [2] => [3] => [4] => " [5] => [6] => attrV"alue2 [7] => " ) [1] => Array ( [0] => attrName=attrValue2, [1] => attrName [2] => [3] => [4] => [5] => [6] => attrValue2 [7] => ) [2] => Array ( [0] => attrName='attr'Value3', [1] => attrName [2] => [3] => [4] => ' [5] => ' [6] => attr'Value3 [7] => ' ) [3] => Array ( [0] => atrybut ="w|'''sc" [1] => atrybut [2] => [3] => [4] => " [5] => [6] => w|'''sc [7] => " ) ) |
|
|
![]() ![]() |
![]() |
Aktualny czas: 19.08.2025 - 02:29 |