I want to take a short string, and manipulate it in PHP so various parts of it can be inserted into various parts of the database.
It’s a way I want to add contact information into my system.
I use a series of short codes to denote what I want the string to do. So:
- NC = New contact
- DESC = A description of the contact
- MB = A cell phone number
- HM = A home phone number
- BS = A business number
- EM = An email address
So for example:
$string = "NC John Doe DESC President USA MB 555123123 HM 12341234 EM john@example.net"
And so on. I can’t see why there needs to be a limit on the length.
What would you do in PHP to make this easy? I want to add phone numbers to the phone table, emails to the email table and contacts to the contact table.
I also have short codes for updates (to add more numbers to existing contacts)
- UPD – Update contact X
- AMB – Add cell
- (Axx – “A” is add)
- I won’t bother with delete/change
$string = "UPD John Doe AMB 55512341233 AEM john2@example.net"
I know it’s a bit of an odd way to get things into a system, but it’s quick to type when I’m on the run.
I Agree with Michael J.V. about using an array. It would be easy to add/change actions
Example: