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.
Not a member yet? Click here to register.
Forgot Password?

preg_replace to preg_replace_callback

Asked Modified Viewed 1,014 times
C
chrome511
C
sorry for my english.
i´m from germany
  • Member, joined since
  • Contributed 73 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
asked
Member

hello
i need help with the /e modifier.

i must change this:

$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?
0 replies

5 posts

C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

IMG bbcode?

We have that are the repository: https://github.com/PHPFusion/PHPFusio...nclude.php
0 replies
C
chrome511
C
sorry for my english.
i´m from germany
  • Member, joined since
  • Contributed 73 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
answered
Member

no bbcode
this is part of an infusion
0 replies
C
chrome511
C
sorry for my english.
i´m from germany
  • Member, joined since
  • Contributed 73 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
answered
Member

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?
Edited by chrome511 on 29-09-2019 19:47,
0 replies
C
chrome511
C
sorry for my english.
i´m from germany
  • Member, joined since
  • Contributed 73 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions
answered
Member

i have build something like this:
$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?
0 replies
C
Chan
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
answered
Super Admin

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'.


$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.
$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.
0 replies

Category Forum

General Discussion

Labels

None yet

Statistics

  • Views 0 views
  • Posts 5 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

C
C
Chan 0
Lead Developer of PHP-Fusion
  • Super Admin, joined since
  • Contributed 3,842 posts on the community forums.
  • Started 232 threads in the forums
  • Answered 6 questions
C
C
sorry for my english.
i´m from germany
  • Member, joined since
  • Contributed 73 posts on the community forums.
  • Started 18 threads in the forums
  • Started this discussions

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet