skip to Main Content

I’m creating a cv page and it has social media section like in image below :
enter image description here

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


  1. you could use regex conditions for the url and based on that you can do if coniditions for the various social media links.

    Login or Signup to reply.
  2. Code it manually, while retrieving social links of relevant user from database, read every link and find which social account is it about.

    If (stristr($linkFromDatabase, "https://facebook.com")){
         // This link is about facebook and icon will be facebook icon
    }
    
    If (stristr($linkFromDatabase, "https://twitter.com")){
         // This link is about twitter and icon will be twitter icon
    }
    

    Add same for every social accounts possible.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search