title: Replace all matched strings from matched position up to the first ' symbol
body: <p>I have a query string that contains <code>$lang</code> keyword, now I want to replace everything before <code>$lang</code> until first occurrence of <code>'</code> symbol with content of another array using loop.</p>
  
  <p>Below is my query string:</p>
  
  <pre><code>select 
  COUNT(t1.id) as total, 
  COUNT(t1.id) as 'total_$lang', 
  CASE t2.`precence`
          WHEN '0' THEN 'Absent'
          WHEN '1' THEN 'Present'
          ELSE 'Unknown'
      END AS series,
  CONCAT(DAYNAME(t1.date),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS ticks,
  CONCAT(DATE_FORMAT(t1.date, '%a'),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS abv,
      courses.no AS label,
  CASE t2.`precence`
          WHEN '0' THEN 'absent_$lang'
          WHEN '1' THEN 'present_$lang'
          ELSE 'unknown_$lang'
      END AS 'attendance_state_$lang',
  CONCAT(DAYNAME(t1.date),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS 'attendance_date_$lang',
  CONCAT(DATE_FORMAT(t1.date, '%a'),' ',DATE_FORMAT(t1.date,'%Y %M %d')) AS 'attendance_date_abv_$lang',
  courses.no AS 'course_num_$lang'
  
  from course_attendances as t1 left join `student_attendances` as t2 on t2.`course_attendance_id` = t1.`id`
  right join courses ON courses.id = t1.course_id
  where t1.`course_id` = '1' AND t1.date BETWEEN '2015-01-01' AND '2015-11-02'
  group by t1.`date`,t2.`precence`
  </code></pre>
  
  <p>Now I want to replace with content of below array</p>
  
  <pre><code>Array
  (
      [total_en] =&gt; Total
      [absent_en] =&gt; Absent
      [present_en] =&gt; Present
      [unknown_en] =&gt; Unknown
      [attendance_state_en] =&gt; Attendance State
      [attendance_date_en] =&gt; Attendance Date
      [attendance_date_abv_en] =&gt; Attendance Date (abv)
      [course_num_en] =&gt; Course Number
  )
  </code></pre>
  
  <p>Just I need the find match case section of question, for any help thanks.</p>