Okey so i know that i can remove letters and numbers from a string by using preg_replace. but here is what im trying to do.
Im using a wordpress plugin called Engage forms, that stores submitted data in a mySQL database.
The tricky part is that the data that's being submitted is not stored cleanly for some reason. (reason being that the devs that made the plugin with some purpurs for this and i cant figuer out how they print out without the unknown numbers and letters.)
Here is what i mean:
I submit the data
- Firstname: Peter
- Lastname: Stormare
- Email: storm@ren.com
- Phone: 0736997385
Here is how the data inside the mySQL database looks and how its being printed out on the webpage:
Very messy
a:4:{s:18:"firstname25601459863853";s:5:"Peter";s:23:"lastnamn77151459863853";s:8:"Stormare";s:19:"email58511459863853";s:13:"Storm@ren.com";s:21:"phone22101459863853";s:10:"0736997385";}
My attempt at cleaning up the data
So ive tried using my little knowledge and take away as much as i can with:
$patterns = array();
$patterns[0] = '/[{}]/';
$patterns[1] = '/[a-x]:[0-9]/';
$patterns[2] = '/[0-9]:/';
$patterns[3] = '/[a-x]:/';
$patterns[4] = '/[":"]/';
$patterns[5] = '/;/';
$patterns[6] = '/namn[1]/';
$replacements = array();
$replacements[2] = '';
$replacements[1] = '';
$replacements[0] = '';
$replacements[3] = '';
$replacements[4] = ' ';
$replacements[10] = ''
echo preg_replace($patterns, $replacements, $leadslist);
Which should output this now:
firstname25601459863853 Peter lastname77151459863853 Stormare email58511459863853 Storm@ren.com phone22101459863853 0736997385
The Big Question
Is there anyway i can now target the random numbers that follow firstname and the rest, without deleting the phone numbers? (the example phone number is 0736997385.
Possible solution
The best solution atm was submitted by user: Pei-turn.
He showed me how to remove any number bigger then 10 digits. Using this pattern in Preg_replace()
$patterns[3] = '/[0-9]{0,9}[0-9]{11,}/';
This works very well. Only thing im worried about is if some data might get removed due to weird future form submissions.