Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Preg match i replace - używanie zmiennej w replace
tosiek
post
Post #1





Grupa: Zarejestrowani
Postów: 142
Pomógł: 0
Dołączył: 7.07.2008

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


Witam. Mam błahy problem z preg match i replace:

  1. <?php
  2. $cks_file2 = preg_match("/bb0100c15b_data    (.*)/", $cks_file, $cks_file_data);
  3. $cks_file2 = preg_replace("/".$cks_file_data[1]."/", $cks_data3, $cks_file);
  4. $cks_file3 = preg_match("/bb0100c15b_sid    (.*)/", $cks_file2, $cks_file_data2);
  5. $cks_file3 = preg_replace("/".$cks_file_data2[1]."/", $cks_sid, $cks_file2);
  6. ?>


I mam problem z dodaniem do zmiennej z preg match przed zmienną / i po /.
I dziwne rzecz po zmianie za pomocą preg replace ucina resztę pliku, też nie wiem czemu ;/
Go to the top of the page
+Quote Post
erix
post
Post #2





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




preg_quote" title="Zobacz w manualu PHP" target="_manual?
Go to the top of the page
+Quote Post
tosiek
post
Post #3





Grupa: Zarejestrowani
Postów: 142
Pomógł: 0
Dołączył: 7.07.2008

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


Coś nie chciało zadziałać, zwracało pusta wartość, ale nie ważne.


Hm... po tych akcjach:
  1. <?php
  2. $cks_file = file_get_contents('edit_forum.txt');
  3. preg_match("/bb0100c15b_data    (.*)/", $cks_file, $cks_file_data);
  4. $cks_file_data2 = preg_replace("/" . $cks_file_data[1] . "/", $cks_data3, $cks_file);
  5.  
  6. preg_match("/bb0100c15b_sid    (.*)/", $cks_file_data2, $cks_file_sid);
  7. $cks_file_sid2 = preg_replace("/".$cks_file_sid[1]."/", $cks_sid, $cks_file_data2);
  8. echo $cks_file_sid2;
  9. ?>


echo wyświetla się Ok. tylko po zapisie wywala się.

plik po preg_replace:
Kod
# Netscape HTTP Cookie File # http://curlm.haxx.se/rfc/cookie_spec.html # This file was generated by libcurl! Edit at your own risk. .phpf.tosiek.pl TRUE / FALSE 1269068361 bb0100c15b_data a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A33%3A%22106310231549c4a5b0437be5.79497465%22%3Bs%3A6%3A%22userid%22%3Bi%3A4%3B%7D .phpf.tosiek.pl TRUE / FALSE 0 bb0100c15b_sid 34c1db13e045583c664fc0a63c9c6127


po zapisie do pliku:
http://wklej.org/id/67380/

zapisuję za pomocą:
  1. <?php
  2. $cks_file2 = file_put_contents('edit_forum.txt', $cks_file_sid2);
  3. ?>
Go to the top of the page
+Quote Post
erix
post
Post #4





Grupa: Moderatorzy
Postów: 15 467
Pomógł: 1451
Dołączył: 25.04.2005
Skąd: Szczebrzeszyn/Rzeszów




A nie możesz po explode" title="Zobacz w manualu PHP" target="_manual przetworzyć całego pliku?
Go to the top of the page
+Quote Post

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: 4.10.2025 - 22:19