I AM LISTENING TO
|
WAS ICH LIEBE
  • Englisch
  • Deutsch

PHP Life Saver of the Week – preg_replace_callback

31. März 2017




PHP Life Saver of the Week – preg_replace_callback

I am currently building a custom slides / template builder for a project, with a lot of moving parts and dynamic logic.

As there are repeating patterns within the slides, each pattern and its logic needs to be neatly separated.  As the slides can be reordered and dropzones can be changed, I need to make sure logic doesn’t break and IDs get updated.

Before reassembling all templates, I am making sure that IDs match the slide and dropzone using a preg_replace_callback

One of the patterns is a simple tab setup, each has its unique ID defined like vl-tab_U1_S1_D1.

The function below passes the found matches through to the anonymous callback function in preg_replace_callback and offers outside data to the function using use($foo). The $dropzone object holds the current unit, slide and dropzone of the pattern, which can be used to replace the current ID with the correct one.

Really nice combo to make magic happen  ;)

BTW here a nice website to testdrive and tweak your Regex : https://regex101.com/

Enjoy coding …




Abonnieren
Benachrichtige mich bei
guest
0 Comments
Inline Feedbacks
View all comments



Alexander

Ich bin ein Full-Stack-Entwickler. Meine Expertise umfasst:

  • Server-, Netzwerk- und Hosting-Umgebungen
  • Datenmodellierung / Import / Export
  • Geschäftslogik
  • API Layer / Action Layer / MVC
  • Benutzeroberflächen
  • User Experience
  • Verständnis für Kundenwünsche und Geschäftsbedürfnisse

 

Ich liebe die Entwicklung, das Design und kenne mich auch mit Serverarchitekturen aus.  Ich würde mich nie vollständig fühlen, wenn einer der Bereiche fehlen würde.

Ich habe ein breites Interessengebiet, deshalb tauche ich ständig in neue Technologien ein und erweitere mein Wissen, wo immer es nötig ist. Die Technologien entwickeln sich schnell und ich genieße es, die neuesten Technologien zu nutzen.

Abgesehen davon bin ich ein friedliebender Kerl, der versucht, Leute um sich herum zu haben, die dasselbe denken.  Ich glaube wirklich an das Prinzip: "Wenn man jemandem hilft, wird einem jemand helfen, wenn man es braucht."

Previous Next