Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Preg_replace to preg_replace_callback

hello
i need help with the /e modifier.

i must change this:

CodeDownload  
$text = preg_replace("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#sie", $locale['MG_UFA_f05'], $text);



to a preg_replace_callback.
can someone help me?
no bbcode
this is part of an infusion
The word for the $locale['MG_UFA_f05'] is "BILD" (picture in english).

If i understand this, it search for an image with the extension jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG on HTTP|FTP and replace it with the $locale.

how must the preg_replace change to preg_replace_callback that it replace it with the $locale or work with $locale?
i have build something like this:
CodeDownload  
$text = preg_replace_callback("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#si",
 function($matches){
 foreach($matches as $match){
 return ($locale['MG_UFA_f05']);
 }
 },
 $text
 );



would this work?
Which version are you using?

In v9, $locale is no longer a superglobal, well maybe semi, but we've isolated them for the most part.

Spend some time with the function 'fusion_get_locale'.

CodeDownload  

$locale = fusion_get_locale('', [LOCALE.LOCALESET.'currency.php', INFUSIONS.'example/locale/'.LANGUAGE.'.php]); // load 2 files locale in addition the current locale.
$locale = fusion_get_locale('global_200'); // get global_200 locale.
$locale = fusion_get_locale(); // returns an array of all compiled locale.


So perhaps you can do it in 2 ways.
1, in your infusion output page file, you can do the set locale method once.
2. set the locale inside your preg function.
CodeDownload  
$text = preg_replace_callback("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#si",
 function($matches){

$locale = fusion_get_locale('', [ ' path-to-your-locale-file' ]);

 foreach($matches as $match){
 return ($locale['MG_UFA_f05']);
 }
 },
 $text
 );



I recommend using method 1 since no point spending resources every time you do a string mutation.
Thread Information
Author
Posted In
Replies
6 posts
Views
126 times
Last Post
Last updated on 16 days ago
Related Threads
You can view all discussion threads in this forum.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You can download attachments in this forum.
Users who participated in discussion: Chan, chrome511