Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use a regex, this should get you started:</p> <pre><code>$sString = '(Bedrijfsnaam:variable1) (Contactpersoon (achternaam):variable2) (E-mail adres:variable3) (OS:variable4) (OS User:variable5) [ID:416129849993661001953:ID]'; if(preg_match_all('#:([^\)]+)#', $sString, $aMatches)) { var_dump($aMatches[1]); } </code></pre> <p><strong>Edit:</strong> You asked me how to capture empty variables. Let me explain what is happening in the regex a little.</p> <p>The <code>#</code>'s are delimiters to tell where the regex starts and stops, let's ignore those.</p> <p>The colon right after the first delimiter (<code>:</code>) matches the colons in the string where you want your "capture" to start.</p> <p>Then the interesting part <code>[^\)]+</code>, this matches everything up to the first parenthesis <code>)</code> it encounters. The brackets <code>[]</code> ( a "character class" ) followed by the <code>^</code> basically means match everything BUT what is followed by the <code>^</code>, in our case a <code>)</code>. The <code>+</code> tells the regex to match <strong>1</strong> or more.</p> <p>So all we have to do to match <strong>0</strong> or more is to use the astericks <code>*</code> which does exactly that.</p> <pre><code>$sString = '(Bedrijfsnaam:) (Contactpersoon (achternaam):variable2) (E-mail adres:) (OS:variable4) (OS User:variable5) [ID:416129849993661001953:ID]'; if(preg_match_all('#:([^\)]*)#', $sString, $aMatches)) { var_dump($aMatches[1]); } </code></pre> <hr> <p>I'm normally not the "hand a guy a fish type". So if you have any questions pertaining what is happening here, let me know.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload