I’m creating a cv page and it has social media section like in image below :
I created an auto add input so user can add social media profile url as much as they want.
Example :
if user has 3 social accounts (can be more) inputs will become like so as array :
<input type="text" name="social[]" id="social" placeholder="social"/>
<input type="text" name="social[]" id="social" placeholder="social"/>
<input type="text" name="social[]" id="social" placeholder="social"/>
And I insert them into database like this in one column:
$social = implode(',', $_POST['social']);
They look like this in database :
https://twitter.com/username,
https://www.facebook.com/username,
https://username.tumblr.com/,
Question
How can I check and replace url coming from database with the correct icon of that website ?
like this :
<a target="_blank" href="<?php echo $facebook; ?>" title="facebook"><i class="fa fa-facebook-square"></i></a>
<a target="_blank" href="<?php echo $twitter; ?>" title="twitter"><i class="fa fa-twitter-square"></i></a>
<a target="_blank" href="<?php echo $tumblr; ?>" title="tumblr"><i class="fa fa-tumblr-square"></i></a>
I’m stuck on it. I realy need your advices, my brain stopped working.
Thanks for all helps.
2
Answers
you could use regex conditions for the url and based on that you can do if coniditions for the various social media links.
Code it manually, while retrieving social links of relevant user from database, read every link and find which social account is it about.
Add same for every social accounts possible.