I am still learning a lot about PHP and changing strings is what interests me. I used preg_match before for things like checking email addresses or just searching for queries.
I just came from this post. What's wrong with my regex? and it was curious why the preg_match_all function produces 2 lines, 1 w / some of the characters devoid, and then another w / desired output.
From what I understand about the function, it is that it passes the string character to character using RegEx to evaluate what to do with it. Can this RegEx be structured in such a way as to bypass the first record of the array and simply produce the desired result?
and you do not need to go to another thread
$str = 'text^name1^Jony~text^secondname1^Smith~text^email1^example-
free@wpdevelop.com~';
preg_match_all('/\^([^^]*?)\~/', $str, $newStr);
for($i=0;$i<count($newStr[0]);$i++)
{
echo $newStr[0][$i].'<br>';
}
echo '<br><br><br>';
for($i=0;$i<count($newStr[1]);$i++)
{
echo $newStr[1][$i].'<br>';
}
This will lead to the conclusion
^ Jony ~
^ Smith ~
^example-free@wpdevelop.com~
Jony
example-free@wpdevelop.com
, . , , , .
,