Gebelik maç soru

0 Cevap php

Birisi zaten bu soruyu sordu eminim, ama google fazla 1 saat arama yaptıktan sonra, ben burada sorumu sormaya karar verdi.

I want to itterate over an array excisting of different strings/texts. These texts contain strings with both ##valuetoreplace## and #valuetoreplace#

Ben preg_matches yapmak istiyorum:

$pattern = '/^#{1}+(\w+)+#{1}$/';
if(preg_match($pattern, $value, $matches, PREG_OFFSET_CAPTURE))
{
   // do something with the #values#
}

VE

$pattern = '/^#{2}+(\w+)+#{2}$/';
if(preg_match($pattern, $value, $matches, PREG_OFFSET_CAPTURE))
{
   //do something with the ##value##
}

This works great. Now my only problem is as follows:

I gibi bir dize varsa

$valueToMatch = 'proceding text #value#';

(I ^ ve $ kullanıldığı gibi) Benim preg_match artık benim değerini bulamıyor.

Soru: nasıl bulabilirim #value# ve ##value##, bu sözleri (multi-line) değerinin ortasında ise endişelenmenize gerek kalmadan?

*In addition: What i want is to find patterns and replace the #value# with a db value and a ##value## with a array value. For example:

$thingsToReplace = 'Hello #firstname# #lastname#, 
How nice you joined ##namewebsite##.';

olmalıdır

'Hello John Doe, 
How nice you joined example.com.'

0 Cevap