Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem Z Preg_replace + Dane W Pliku Txt
Qbin2001
post
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 3.09.2006

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


Witam. Mam problem z wyświetlaniem danych z pliku.

Plik index.php zawiera string $output w którym są skrócone dane, które podmienia na właściwe za pomocą funkcji replace_more_news.
Funkcja replace_more_news podmienia dane wykonując jednocześnie funkcję odczytu danych z pliku files.txt (zawierających odpowiednie dane (inna funkcja zapisuje dane w tym pliku - nie dodawałem jej bo działa ok.)

Niestety porównanie danych z $file i $single_line_arr[0] - w if($file == $single_line_arr[0]) - zdaje sienei działać, mimo iż obie dane są identyczne.

Może mi ktoś pomóc ?

Poniżej zamieszczam listingi obu plików:


index.php

  1. <?
  2.  
  3. ////////////////////////////////////////////////////////
  4. // Function: replace_more_news
  5. // Description: Replaces news charactars
  6.  
  7. function replace_more_news ($way, $sourse){
  8.  
  9. if ($way == 'show'){
  10. $find  = array(
  11.  
  12. /* 01 */  "/[filename=(.*?)]/i",
  13. /* 02 */ "/[downloads=(.*?)]/i",
  14. /* 03 */ "/[filesize=(.*?)]/i"
  15.  
  16. );
  17. $replace = array(
  18.  
  19. /* 01 */  "<a href=\"img/1\">1</a>",
  20. /* 02 */  get_download_values('1', 'downloads'),
  21. /* 03 */  get_download_values('1', 'size')
  22. );
  23.  
  24. $sourse  = stripslashes($sourse);
  25.  
  26. } 
  27.  
  28. return preg_replace($find, $replace, trim($sourse));
  29. }
  30.  
  31.  
  32.  
  33. ////////////////////////////////////////////
  34. //Function: get_download_values
  35. //Description: Gets the size and number of DL for a file 
  36.  
  37. function get_download_values($file, $what){
  38. $file_db_file = 'files.txt';
  39. $file_db_content = file($file_db_file);
  40. foreach($file_db_content as $single_line){
  41. $single_line_arr = explode("|", $single_line);
  42. if($file == $single_line_arr[0]){
  43. return ($what == "size" ? $single_line_arr[1] : $single_line_arr[2]);
  44. }
  45. }
  46. }
  47.  
  48.  
  49.  
  50. $output = "[filename=test1]<br />[filesize=test1]<br />[downloads=test1]<br /><br /><br />[filename=test2]<br />[filesize=test2]<br />[downloads=test2]";
  51.  
  52. $output = replace_more_news ('show', $output);
  53.  
  54. echo $output;
  55.  
  56. ?>



files.txt

Kod
test1|<nobr>size test 2</nobr>|<nobr>downloads test 1</nobr>|
test2|<nobr>size test 2</nobr>|<nobr>downloads test 2</nobr>|


Z góry dziękuję :-)
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 19:51