Jump to content

[SOLVED] Is there a limit to string length of an array, or to an echo/print?


lonewolf217

Recommended Posts

I have a table in my database and one particular column can have pretty lengthy values

 

when retrieving the data from the database and displaying it, the value is always cut off at a random place, even though the data is intact in the database.  Is there any limit to how much data either mssql_fetch_row or echo/print can hold?

Link to comment
Share on other sites

I have a table in my database and one particular column can have pretty lengthy values

 

How long is "pretty lengthy"?

 

when retrieving the data from the database and displaying it, the value is always cut off at a random place, even though the data is intact in the database.  Is there any limit to how much data either mssql_fetch_row or echo/print can hold?

 

If you get the same row twice, does it cut off at different places?  Or the same?

 

Echo/print has no limit to my knowledge.  I doubt that mssql_fetch_row has a limit either, unless the result exceeds php's memory limit.

Link to comment
Share on other sites

well its very curious.  I have a string that is abnormally long, perhaps 500 characters that gets cut off. This is a sample of the code I am using

 

I get the record from the database

if($connection = mssql_connect($myServer,$myUser,$myPass)){
mssql_select_db($myDB,$connection);
if($sql = mssql_query("SELECT * FROM KBArticles WHERE ID=" . $strID)){
	$row = mssql_fetch_array($sql);
        }
}

 

then later I display it.

linkURLs merely finds a URL in the description and converts it to a link. I have tried commenting out that line and it makes no difference

<b>Description:</b></TD><TD> 
<?php
$Desc = linkURLs($row[3]);
$Desc = nl2br($Desc);
echo $Desc;
?>

 

the part that confuses me is that on this page i have a link to edit the item.  this edit page is still in .asp as I have not had a chance to convert it yet.  when editing the item the entire description is displayed.  when viewing the item in this .php however, the description is cut off.

 

I dont think I missed anything, but I cannot figure out anything from the code that would cause the description to be truncated.  it gets cut off in the middle of a word, no special characters at all

Link to comment
Share on other sites

one value I have in the database is

When working with a CCR cluster, it is recommended by Microsoft to not use the cluster administrator utility to fail over the cluster as it is not aware of the Exchange resources. Instead, open Exchange Management Shell and use this command    Edit the fields appropriately for your setup, then execute it and it will fail over the cluster as long as there are no errors.  Recommend saving this into a .ps1 file and keeping it on each node of the cluster for failover use    move-clusteredmailboxserver -identity:e2k7ccr -targetmachine:exccr1 -movecomment:"This is not a test!"

 

and when I try to display this using the code I previously pasted, I see this

When working with a CCR cluster, it is recommended by Microsoft to not use the cluster administrator utility to fail over the cluster as it is not aware of the Exchange resources. Instead, open Exchange Management Shell and use this command

Edit the fi

Link to comment
Share on other sites

One thing that I have figured out is that with spaces, I am only displaying 255 characters.  The question is, where is this limitation coming from.  Is it happening when I pull it from the database, or is it happening when I am outputting the data ?

 

here is what I am using once again

 

to pull the row from the database

if($connection = mssql_connect($myServer,$myUser,$myPass)){
mssql_select_db($myDB,$connection);
if($sql = mssql_query("SELECT * FROM KBArticles WHERE ID=" . $strID)){
	$row = mssql_fetch_row($sql);
}
}

 

and then to output it

<b>Description:</b></TD><TD> 
<?php 
$Desc = linkURLs($row[3]);
$Desc = nl2br($Desc);
echo $Desc;
?>
</TD></TR>

Link to comment
Share on other sites

it is irrelevant because my string still gets truncated even when I comment out this line. 

If I just run <?php echo $row[3]; ?> the string gets truncated

 

but here it is anyway

function linkURLs($string) {
//make sure there is an http:// on all URLs ***/
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
//make all URLs links ***/
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@\(\)]+[\w\/])/i","<a href=\"$1\" target=_new>$1</A>",$string);

return $string;
}

Link to comment
Share on other sites

My guess is that something else on the web page is causing a fatal runtime error and you are getting content that has been blocked/buffered/transfered at the time the fatal error occurred (php 5.2.4 had a bug where they forgot to flush the output buffer when a page terminated with a fatal runtime error.)

 

I think we need to see all your code, not just a few snippets of it, and add the following two lines after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

 

What do your see when you do a "view source" in your browser?

 

Could you add an echo statement to your code prior to where this problem is that is outputting a fairly long string (100+) of characters to see if this changes the point where the output is cut off. This would indicate if the problem is the whole web page or just the data from the database.

Link to comment
Share on other sites

those two lines made no difference.  here is my entire page

 

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);

$strID = $_GET['ID'];

if($connection = mssql_connect($myServer,$myUser,$myPass)){
mssql_select_db($myDB,$connection);
if($sql = mssql_query("SELECT * FROM KBArticles WHERE ID=" . $strID)){
	$row = mssql_fetch_row($sql);
}
else {
	echo "Error: " . mysql_error();
}
}
else {
echo "Error: " . mysql_error();
}

//this function will find all URL's in the description and convert them to links
function linkURLs($string) {
//make sure there is an http:// on all URLs
$string = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i", "$1http://$2",$string);
//make all URLs links
$string = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@\(\)]+[\w\/])/i","<a href=\"$1\" target=_new>$1</A>",$string);

return $string;
}
?>

<html>
<body bgcolor="CCCCCC" alink="blue" vlink="blue">

<center>
<TABLE border=1>
<TR><TD>
<b>Product:</b></TD><TD> <?php echo $row[0]; ?>
</TD></TR>
<TR><TD>
<b>Category:</b></TD><TD> <?php echo $row[1]; ?>
</TD></TR>
<TR><TD>
<b>Abstract:</b></TD><TD> <?php echo $row[2]; ?>
</TD></TR>
<TR><TD valign=top>
<b>Description:</b></TD><TD> 
<?php 
$Desc = linkURLs($row[3]);
$Desc = nl2br($Desc);
echo $Desc;
?>
</TD></TR>
<TR><TD>
<b>Created By:</b></TD><TD> <?php echo $row[4]; ?>
</TD></TR>
<TR><TD>
<b>Last Modified:</b></TD><TD> <?php echo $row[5]; ?>
</TD></TR>
</TABLE>


<a href="editkb.asp?ID=<?php echo $row[6] ?>" target=_self><img src="\Images\edit.jpg"></a>
<a href="deletekb.php?ID=<?php echo $row[6] ?>" target=_self onClick="return confirm('Are you sure you want to delete this KB article?');"><img src="\Images\delete.jpg"></a>
</center>
</body>
</html>

Link to comment
Share on other sites

What do your see when you do a "view source" in your browser?

 

Could you add an echo statement to your code prior to where this problem is that is outputting a fairly long string (100+) of characters to see if this changes the point where the output is cut off. This would indicate if the problem is the whole web page or just the data from the database.

What about these two items?

 

Since we don't have access to your data in your database or your server, we only know what you have posted. Tell us or post everything you see. For example, do the items that you echo later on the page display? Post the "view source" of the page. Echo strlen($row[3])

Link to comment
Share on other sites

sorry missed that part. here is the view source of the page

<html>
<body bgcolor="CCCCCC" alink="blue" vlink="blue">

<center>
<TABLE border=1>
<TR><TD>
<b>Product:</b></TD><TD> Exchange 2007</TD></TR>
<TR><TD>
<b>Category:</b></TD><TD> Configuration</TD></TR>
<TR><TD>

<b>Abstract:</b></TD><TD> How to properly fail over a CCR cluster</TD></TR>
<TR><TD valign=top>
<b>Description:</b></TD><TD> 
When working with a CCR cluster, it is recommended by Microsoft to not use the cluster administrator utility to fail over the cluster as it is not aware of the Exchange resources. Instead, open Exchange Management Shell and use this command<br />
<br />
Edit the fi</TD></TR>
<TR><TD>
<b>Created By:</b></TD><TD> username</TD></TR>

<TR><TD>
<b>Last Modified:</b></TD><TD> Jun 20 2008  1:48PM</TD></TR>
</TABLE>


<a href="editkb.asp?ID=76" target=_self><img src="\Images\edit.jpg"></a>
<a href="deletekb.php?ID=76" target=_self onClick="return confirm('Are you sure you want to delete this KB article?');"><img src="\Images\delete.jpg"></a>
</center>
</body>
</html>

 

and when I do Echo strlen($row[3]) I get "255".

 

I did put an echo statement in right at the beginning that outputted a very lengthy statement and it did not change at all what was displayed from the database

 

this is the entry directly from the database

Exchange 2007	Configuration	How to properly fail over a CCR cluster	When working with a CCR cluster, it is recommended by Microsoft to not use the cluster administrator utility to fail over the cluster as it is not aware of the Exchange resources. Instead, open Exchange Management Shell and use this command    Edit the fields appropriately for your setup, then execute it and it will fail over the cluster as long as there are no errors.  Recommend saving this into a .ps1 file and keeping it on each node of the cluster for failover use    move-clusteredmailboxserver -identity:e2k7ccr -targetmachine:exccr1 -movecomment:"This is not a test!"	username 2008-06-20 13:48:18.380	76

 

If i still missed something, I apologize, I will get it next time

 

Link to comment
Share on other sites

I think I found the solution, it was a problem with my database and/or how php handles it.

 

I had my description field set as varchar(8000) which php apparently cannot handle larger than 255. Once I changed it to a text filed, it is working properly.  I never though this could be a problem because the same structure had worked when my page was written in .asp.  Oh well!

 

found this on google

http://bugs.php.net/bug.php?id=25544

 

thanks anyway for all your help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.