Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> zamiana stringa na array
Randallmaster
post
Post #1





Grupa: Zarejestrowani
Postów: 677
Pomógł: 11
Dołączył: 18.11.2009

Ostrzeżenie: (0%)
-----


W jaki sposób poniższy string można zamienić na tablicę?

width: 500px; height: 500px; border-width: 5px; border-radius: 30px;

[width] => 500
[height] => 500
[border-width] => 5
itd.
(IMG:style_emoticons/default/questionmark.gif) ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
trzczy
post
Post #2





Grupa: Zarejestrowani
Postów: 460
Pomógł: 49
Dołączył: 5.06.2011

Ostrzeżenie: (0%)
-----


array_walk II (IMG:style_emoticons/default/smile.gif)

  1. <?php
  2. $str = 'width: 500px; height: 500px; border-width: 5px; border-radius: 30px;';
  3. $array2 = preg_split('/([\s;:]+)/', $str);
  4. $array2, function ($el) use (&$array, &$key) {
  5. if ($key) {
  6. $array[$key] = $el;
  7. $key = null;
  8. } else $key = $el;
  9. }
  10. );
  11. print_r($array);
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: 29.12.2025 - 19:34