Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [RegularExpressions]+(Pobieranie danych)
Wankster
post
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? (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Mam string:
Kod
attrib1='jakis tekst'"```', attrib2 = "jakis " text'", attrib3 =`'tekst"jakis`, attrib4= ''''''
I chciałbym uzyskać taką tablicę:
Kod
Array

(

    [0] => Array

    (

  [0] => attrib1

  [1] => attrib2

  [2] => attrib3

  [3] => attrib4

    )

    [1] => Array

    (

  [0] => jakis tekst'"```

  [1] => jakis " text'

  [2] => 'tekst"jakis

  [3] => ''''

    )

)
Jest to wykonalne?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Wankster
post
Post #2





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 (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) -- troszkę zmodyfikowałem):[php:1:40b820874b]<pre><?php

$str = 'attrName="attrV"alue2", attrName=attrValue2, attrName='attr'Value3', atrybut ="w|'''sc" ';

$regexp = '/([a-zA-Z0-9]+)( )?=( )?((')|"|)((?(IMG:http://forum.php.pl/style_emoticons/default/sad.gif) ?:4)|(?(3)[^']|[^"]))*)(4)(?:s|,|$)/U';

preg_match_all( $regexp, $str, $matches, PREG_SET_ORDER );

print_r( $matches );

?></pre>[/php:1:40b820874b]I mam taki wynik:
Kod
Array

(

    [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] => "

        )



)
Tylko, co teraz dodać do tego regExp-a, żebym mógł też używać ` wraz z ' oraz " :?: 8O
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.09.2025 - 21:29