0

I've bought a script that uses a database to for elements like the page site, meta tags etc. The problem is that when the data is added to the page a space or two is also added. The script is using

    <?php echo siteinfo("sitetitle");?>

to add the data to the page, but I also found this function:

    function siteinfo($att)

{

    include("linkmysql.php");
    $att=mysql_real_escape_string($att);
    $query="Select value from settings where attribute='$att'";

    if ($q=mysql_query($query,$link))

        if ($r=mysql_fetch_array($q))

        {

            $r[0]=stripslashes($r[0]);

            return $r[0];

        }

    return FALSE;

}

yet I can't work out how it's adding the space and how to remove it so would be grateful for any help. I've checked the database and the space isn't there so it's only being added when the code is added to the page.

Thanks

5
  • 2
    You actually bought this? Maybe space is in HTML, or in database. Commented Dec 14, 2011 at 13:45
  • There's no reason for additional spaces because of that script. But blank spaces in the source-code does not matter anyway. How does your rendered html look like? Commented Dec 14, 2011 at 13:46
  • Look at the "view" code ... if it's something like <title> <?php echo ... ; ?> </title> you're gonna have spaces there; either that or there are spaces in the database... those are the 2 most obvious cases anyway. Commented Dec 14, 2011 at 13:46
  • That code isn't adding any spaces in itself. Can you provide an example of a code block using siteinfo() and the output? Commented Dec 14, 2011 at 13:46
  • well my boss bought it and I'm trying to get rid of errors in it lol. I've checked the view code and the spaces aren't there at all. The siteinfo() block, such as <title><?php echo siteinfo("pagetitle");?></title> will out put <title> Home</title> Commented Dec 14, 2011 at 13:53

2 Answers 2

3

Replace this return $r[0]; with this return trim($r[0]);.

Rewritten, couldn't look at it.

function siteinfo($att)
{

    require_once 'linkmysql.php';

    $att = mysql_real_escape_string($att);

    $query = "SELECT value FROM settings WHERE attribute = '$att' LIMIT 1";

    $query = mysql_query($query, $link);

    if ($query)
    {
        if ($r = mysql_fetch_array($query))
        {
            $r[0] = stripslashes($r[0]);
            return trim($r[0]);
        }
    }

    return false;
}
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks but that didn't work, it removed all the text, but kept the spaces instead lol
Haha impossibru. Post HTML, post screenshot of row in database (select it, if there are spaces you should see it).
the html is <title><?php echo siteinfo("sitetitle");?></title> I'm not sure how to post a screengrab though
It looks fine, I think stripslashes is not necessary... go to your settings table in database, find sitetitle (Home), click edit, select it with mouse, and see if there are any spaces.
I've tried that and there's no spaces there at all, that's what's really baffling me
0

If this function is really where it happens, then you may need an additional 'trim'.

Try to replace this : $r[0]=stripslashes($r[0]); by $r[0]=trim(stripslashes($r[0]));

[EDIT :] Following the comments, it could be the include("linkmysql.php"); file that contains additional space.

That would explain why you get a space character before the title.

Please check for any space before the <?php or after the ?> in linkmysql.php file.

5 Comments

Then it is not in this function nor in the database. Please paste the HTML source in pastebin, and give us a link to see where the spaces are.
At the moment it's all password protected so I can't paste a link, but the html is <title><?php echo siteinfo("pagetitle");?></title> which is outputting <title> Home Page</title>
The only thing I can think of is that linkmysql.php contains an additional space somewhere outside the php brackets. Please check that.
This is the code in the linkmysql.php file: <?php include("../includes/config.php"); $link = mysql_connect($hostname, $dbusername, $dbpassword); mysql_select_db("$databasename"); ?> and the config.php is only the database details
Then drill down to config.php and check for extra spaces there also

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.