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





Grupa: Zarejestrowani
Postów: 8 068
Pomógł: 1414
Dołączył: 26.10.2005

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


Dużo wad ma ten regexp.

Proszę banalna metoda zaczerpnięta z Stacka:
  1. function BreakCSS($CSS) {
  2. $results = array();
  3.  
  4. foreach(explode(';', $CSS) AS $attr)
  5. if (strlen(trim($attr)) > 0) // for missing semicolon on last element, which is legal
  6. {
  7. list($name, $value) = explode(':', $attr);
  8. $results[trim($name)] = trim($value);
  9. }
  10. return $results;
  11. }
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 - 00:56