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
trueblue
post
Post #2





Grupa: Zarejestrowani
Postów: 6 809
Pomógł: 1828
Dołączył: 11.03.2014

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


  1. $styles = "width: 500px; height: 500px; border-width: 5px; border-radius: 30px; background-image:url(\"aaa\")";
  2. $styles=str_replace(",\" \"","", "{\"" . strtr($styles, array(";"=>"\",\"",":"=>"\":\"","\""=>"'")) . "\"}");
  3. $json = json_decode($styles, true);
  4. $keys = array_map('trim', array_keys($json));
  5. $data = array_map('trim', $json);
  6. $result = array_combine($keys, $data);
  7. print_r($result);


//poprawione.

Ten post edytował trueblue 23.03.2017, 18:47:37
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: 26.12.2025 - 11:50