|
 |
|
Codewalkers Forums
> PHP Related
> PHP Coding
|
php5 - Issues with Explode
Discuss Issues with Explode in the PHP Coding forum on Codewalkers. Issues with Explode Having problems with a PHP script you are coding? This is the place to get help!
|
|
|
|
 |
|
|
|
|

Codewalkers Forums Sponsor:
|
|
|

February 16th, 2013, 03:34 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 1
Time spent in forums: 19 m 58 sec
Reputation Power: 0
|
|
|
php5 - Issues with Explode
I have long descriptions stored in the database. Until today I haven't had any issues with using the explode function to display text on the webpage.
I am noticing that if my descriptions are really long the array cuts off text.
For Example, this is what my array results look like using explode:
Array (
=> /path/to/url.php [1] => /image/path/image.jpg [2] => Title [3] => /image/path/image2.jpg [4] => This is the description can be hundreds of characters long, even thousands, [5] => Smaller Description [6] => 6 [7] => Yes )
However, when the description [4] is real long it seems to limit the number of characters to around 1000 total and it looks like this.
Array (
=> /path/to/url.php [1] => /image/path/image.jpg [2] => Title [3] => /image/path/image2.jpg [4] => This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousandsThis is the description can be hundreds of characters long, even thousandsThis is the description can be hundreds of characters long, even thousandsThis is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description can be hundreds of characters long, even thousands This is the description ) <--- Stops here and doesnt show [5], [6] and [7]
Anybody know what is causing this and how to resolve this issue?
I would prefer not to have to limit the number of characters in my description [4] field.
The data is stored in a field with the following characteristics: varchar(2000)
I have also verified that the data is still in the database (visually using phpmyadmin)
Any insights or ideas on how to overcome this issue would be appreciated.
Steve
|

February 19th, 2013, 06:13 AM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
|
can you replicate it in php? (post the source here)
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.
|

February 19th, 2013, 01:50 PM
|
|
Me
|
|
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,263
 
Time spent in forums: 2 Weeks 1 Day 5 h 50 m 53 sec
Reputation Power: 9
|
|
|
there is nothing wrong with explode. it can handle much more than 1k characters (max would be memory dependent, not the function itself). Those appear to be print_r of the array. Print_r doesn't have a limitation on size either. Is there maybe a less that symbol (< )somewhere in the text that html is parsing as the open of an html tag that has no close? view the source of the page and check if you see the entire text that you were expecting. Other than that, can you post your php code so that we can check for errors and perhaps the full text of your example description that you are having problems with.
|

February 20th, 2013, 10:23 AM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 26 m 56 sec
Reputation Power: 0
|
|
|
For some reason, I wasn't able to login with my old account and emails are not getting to me, so I created a new one to get going.
So, here is my code: I didnt originally write it, but have been modifiying over the years.
This is the relevant part within the function.
$result = mysql_query("SELECT p.productcode, p.product, p.list_price, p.productid, GROUP_CONCAT(DISTINCT c.price), GROUP_CONCAT(DISTINCT c.quantity), GROUP_CONCAT( DISTINCT x.value ORDER BY fieldid SEPARATOR '|'), p.descr , p.fulldescr FROM cart_products AS p, cart_pricing AS c, cart_extra_field_values AS x WHERE p.productid = c.productid AND c.productid = x.productid AND p.productid = '$id' AND c.variantid = '$variant' GROUP BY productcode");
if ( mysql_num_rows($result) == 0)
{
print 'Unable to get product information from database at this time. Please <a href="/contact/index.php">contact us</a> for information';
}
else
{
$row = mysql_fetch_array($result);
$productcode = $row['0'];
$fulldescr = $row['8'];
$prices = explode(',', $row['4']);
rsort($prices);
$quantity = explode(',', $row['5']);
$extras = explode('|', $row['6']);
sort($quantity);
print "<tr>\n";
print "<td>\n";
if ($link =='1')
{
print "<a href='".$extras[0]."'><img itemprop='image' src='".$extras[3]."' alt='".$extras[5]."'></a>";
}
else
{
print "<img itemprop='image' src='".$extras[3]."' alt='".$extras[5]."'>";
}
print "</td>\n";
print "<td><strong>\n";
if ($link == '1')
{
print "<a href='".$extras[0]."'><span itemprop='name'>".$extras[5]."</span></a>";
}
else
{
print $extras[5];
}
print "</strong><br />";
print "<span itemprop='description'>".$fulldescr."</span>";
print "</td>\n";
Here is a sample data within the $extra field that gets exploded.
$extras[0] = /bcc/xy100/humidity-player98765.php
$extras[1] = /images/brand/xy100-123.jpg
$extras[2] = LOBO Brand
$extras[3] = /images/small/xy100-123.jpg
$extras[4] = The XY100-123 is a beta jogger with an internal densor for measuring and recording temperature and humidity readings. The beta jogger has a -20C to 70C and 15% to 95% RH measurement range with 0.21C and 3.5% RH accuracy. The display shows current temperature and humidity readings, recording mode, battery level and alarm status. The XY100 Series of beta joggers has a user-replaceable battery, software-selectable sampling rate of 1 second to 18 hours and stores up to 84,650 measured readings before download to computer is necessary. Simply connect the USB cable (supplied with the LOBOnare SHO Software) to the USB Port on your Windows 7, Vista or XP PC Computer and the LOBOnare software will configure your data logger and download the data for analysis. LOBOnare SHO software is required (sold separately) for setup and download of recorded data. Data can be exported and graphed within the software.
$extras[5] = XY100 Humidity Beta Jogger with 375% Accuracy
$extras[6] = 6
$extras[7] = Yes
If add the following text "Data can be exported and graphed within the software." to $extras[4] only a partial of $extras[5] is displayed on the page (using the code above)
I actually dont use extras[4] on the page, but so it really isnt needed here. I use for something else but store it in the database.
Your input would be appreciated.
Steve
|

February 20th, 2013, 10:58 AM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
your query is working fine?
id break out this:
Code:
$result = mysql_query("SELECT p.productcode, p.product, p.list_price, p.productid, GROUP_CONCAT(DISTINCT c.price), GROUP_CONCAT(DISTINCT c.quantity), GROUP_CONCAT( DISTINCT x.value ORDER BY fieldid SEPARATOR '|'), p.descr , p.fulldescr FROM cart_products AS p, cart_pricing AS c, cart_extra_field_values AS x WHERE p.productid = c.productid AND c.productid = x.productid AND p.productid = '$id' AND c.variantid = '$variant' GROUP BY productcode");
into:
Code:
$query = "SELECT p.productcode, p.product, p.list_price, p.productid, GROUP_CONCAT(DISTINCT c.price), GROUP_CONCAT(DISTINCT c.quantity), GROUP_CONCAT( DISTINCT x.value ORDER BY fieldid SEPARATOR '|'), p.descr , p.fulldescr FROM cart_products AS p, cart_pricing AS c, cart_extra_field_values AS x WHERE p.productid = c.productid AND c.productid = x.productid AND p.productid = '$id' AND c.variantid = '$variant' GROUP BY productcode";
$result = mysql_query($query);
and echo $query to ensure the sql call is not returning -1.
a better check would be to use:
Code:
$count = mysql_num_rows($result);
if ( $count > 0)
instead of:
Code:
if ( mysql_num_rows($result) == 0)
|

February 20th, 2013, 12:19 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 26 m 56 sec
Reputation Power: 0
|
|
|
The query itself is working fine.
It is result in the $extras array that is not working correctly when there is lots of data.
Steve
|

February 21st, 2013, 09:09 AM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
|
have you checked your errors file?
|

February 21st, 2013, 03:27 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 26 m 56 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by DavidMR have you checked your errors file? |
Which errors file are you referring too?
It is not creating an error, it is simply chopping information off.
Steve
|

February 21st, 2013, 03:35 PM
|
 |
Contributing User
|
|
Join Date: Apr 2007
Location: Galway
Posts: 1,360

Time spent in forums: 4 Weeks 1 Day 23 h 38 m 14 sec
Reputation Power: 8
|
|
|
have you tried echo-ing $row['6'] ? to see if its in there?
|

February 24th, 2013, 07:22 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 4
Time spent in forums: 26 m 56 sec
Reputation Power: 0
|
|
|
row[5] and row [6] are not there and row[4] is incomplete.
However, if I reduce the amount of characters in row[4] then row[5] and row [6] are there and row[4] is complete.
Steve
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|