title: Doctrine : how to use Replace function
body: <p>I need your help to build my query with Doctrine. I am a symfony beginner.
  Firstly I built my query inside MySQL SQL tab and it's working fine.</p>
  
  <pre><code>SELECT * 
  FROM contact
  WHERE insee like '03%'
  ORDER BY (LENGTH(tif) - LENGTH(REPLACE(tif,";",""))) DESC
  
  To be more precise, my tif field looks like that : 
  1 - 01.02.01.02;01.02.03.04;01.05.06 (3 subsets)
  2 - 01.02.03.08.07.01.02.03.08.0701.02.03.08.07; (1 subset)
  3 - 01.02.01;02.06.05 (2 subsets) 
  </code></pre>
  
  <p>I need to get the number of codes order by desc so as to get the order 1,3,2.</p>
  
  <p>Now I tried to build it in my repository class on Symfony
  I found out that replace function doesn't exist upon Doctrine so I tried to skirt it by doing what follows : </p>
  
  <pre><code>$qb = $this-&gt;getEntityManager()
              -&gt;createQueryBuilder()
              -&gt;select('c')
              -&gt;from('SgaContactBundle:Contact', 'c')
              -&gt;where('c.insee LIKE :insee')
              -&gt;setParameter('insee', '%' . $insee . '%');
  
  $qb-&gt;orderBy($qb-&gt;expr()-&gt;diff(
              $qb-&gt;expr()-&gt;length('c.tif'), 
              $qb-&gt;expr()-&gt;length(preg_match_all('/;/i', 'c.tif')) ),
              'DESC');
  return $qb-&gt;getQuery()
            -&gt;getResult();
  </code></pre>
  
  <p>Finally I've got this error : </p>
  
  <pre><code> [Syntax Error] line 0, col 99: Error: Expected StateFieldPathExpression | string | 
   InputParameter | FunctionsReturningStrings | AggregateExpression, got '0'
  </code></pre>
  
  <p>What can I do in order to replace "Replace function" ?
  I tried preg_replace, preg_match and finally preg_match_all but something goes wrong.</p>
  
  <p>Thanks for your help guys</p>