Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> preg_replace_callback
Jarod
post
Post #1





Grupa: Zarejestrowani
Postów: 1 190
Pomógł: 27
Dołączył: 23.04.2005

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


Natrafiem w manualu na taką funkcję jak preg_replace_callback. Wiem do czego to służy ale nie rozumiem poniższego wywołania

  1. <?php
  2. preg_replace_callback("|(d{2}/d{2}/)(d{4})|", array( __CLASS__, 'getRecord' ), $text);
  3. ?>


Wiem, że __CLASS__ zwraca nazwę bieżącej klasy ale nie rozumiem co daje:
  1. <?php
  2. array( __CLASS__, 'getRecord' )
  3. ?>


Może mi ktoś to wytłumaczyć?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Jarod
post
Post #2





Grupa: Zarejestrowani
Postów: 1 190
Pomógł: 27
Dołączył: 23.04.2005

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


Podobną rzecz widziałem w klasie hwao (metoda generate)
  1. <?php
  2.  
  3. class ConfigCreator {
  4. public $sClassName = 'Config';
  5. static protected $aConfig = array();
  6. const RegEx = '@%([^%]+)%@';
  7.  
  8. public function __construct( $sClassName = 'Config' ) {
  9. $this->sClassName = $sClassName;
  10. }
  11.  
  12. public function Generate( $sPath = null, $sSavePath = null ) {
  13. $sPath  = is_null( $sPath ) ? './config.ini.php' : $sPath;
  14. $aConfig = parse_ini_file( $sPath, true );
  15. $sSource = $this->getHeader();
  16. $sSavePath = is_null( $sSavePath ) ? './config.php' : $sSavePath;
  17. foreach( $aConfig As $sKey => $aLine ) {
  18. foreach( $aLine As $sName => $sValue ) {
  19. $sValue = preg_replace_callback( self::RegEx, array( __CLASS__, '__ConfigPaser' ), $sValue );
  20. self::$aConfig[strtolower($sKey.$sName)] = $sValue;
  21. $sSource .= $this->getLine( $sKey.$sName, $sValue );
  22. }
  23. }
  24. $sSource .= $this->getFooter();
  25.  
  26. file_put_contents( $sSavePath, $sSource );
  27. }
  28.  
  29. static protected function & __ConfigPaser( & $aInput ) {
  30. return self::$aConfig[strtolower($aInput[1])];
  31. }
  32.  
  33. protected function getLine( $sName, $sValue ) {
  34. $sValue = str_replace( ''', ''', $sValue );
  35. if( substr( $sValue, -1, 1 ) == '' ) {
  36. $sValue .= '';
  37. }
  38.  
  39. return '
  40. static public $'.$sName.' = ''.$sValue.'';';
  41. }
  42.  
  43. }
  44. ?>


Ten post edytował J4r0d 2.01.2007, 07:00:15
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: 14.10.2025 - 07:22