1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problem with the use of sprint

Discussion in 'PHP' started by themaster, Jun 20, 2017.

  1. #1
    Is anyone can help me about why I am getting this error?
    PHP Warning: sprintf(): Too few arguments in but no sprintf in
    SEMrush
    The related function is:
    function httpcheckif(){
      return sprintf(
        "%s://%s%s",
        isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http',
        $_SERVER['SERVER_NAME']
      );
    }
    PHP:
     
    Solved! View solution.
    Last edited by a moderator: Jun 20, 2017
    themaster, Jun 20, 2017 IP
    SEMrush
  2. #2
    You have one too many %s in the sprintf.
    The correct line should be:
    
    "%s://%s",
    
    Code (markup):
     
    PoPSiCLe, Jun 20, 2017 IP
    themaster likes this.
  3. themaster

    themaster Well-Known Member

    Messages:
    934
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thanks :)
     
    themaster, Jun 20, 2017 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,401
    Likes Received:
    1,876
    Best Answers:
    245
    Trophy Points:
    515
    #4
    printf is one of those commands I never really understood why they exist in the first place.... as if string addition is so magically hard or that it's somehow worth running a parser under a parser under an interpreter.

    Which is why I'd have scrapped that and simply done:
    
    function httpcheckif(){
    	return (
    		isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http'
    	) . '://' . $_SERVER['SERVER_NAME'];
    }
    
    Code (markup):
    Even in C all "printf" type commands are is a legacy of the fact that the early compilers were all single-pass trash... that it even exists in modern languages like PHP is more a monument to stupidity than it is functionality.
     
    deathshadow, Jun 24, 2017 IP