473,796 Members | 2,648 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

unpack a string

I have used this function to create a string called $headers:

function GetHeaders($fil e_name){
return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
<th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
<th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
<th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
Date</a></th>
<th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
<th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
<th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
<th><a href='".$file_n ame."&order_by= destination'>De stination</a></
th>
<th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
}

Now I want to unpack the $header array and create two strings,
called s1 and s2. I want s1 to be field names for excel and s2 to
be the column names. For example l_e is the field name and L_E is
capitalized to be the column header in Excel. In other words, I want
is the two fields after the order_by= without the 'and the </a>.

How to use unpack?

s1=unpack($head ers/37, 9, $data)

I don't know how to use unpack but I have the $header array as the
string, I counted 37 characters to the word order_by and the word
order_by= is 9 characters I want to grab that word before the '.
How do I make use of the unpack function to get what I want?

tia,
Sep 9 '08 #1
17 2319
JRough wrote:
I have used this function to create a string called $headers:

function GetHeaders($fil e_name){
return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
<th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
<th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
<th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
Date</a></th>
<th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
<th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
<th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
<th><a href='".$file_n ame."&order_by= destination'>De stination</a></
th>
<th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
}

Now I want to unpack the $header array and create two strings,
called s1 and s2. I want s1 to be field names for excel and s2 to
be the column names. For example l_e is the field name and L_E is
capitalized to be the column header in Excel. In other words, I want
is the two fields after the order_by= without the 'and the </a>.

How to use unpack?

s1=unpack($head ers/37, 9, $data)

I don't know how to use unpack but I have the $header array as the
string, I counted 37 characters to the word order_by and the word
order_by= is 9 characters I want to grab that word before the '.
How do I make use of the unpack function to get what I want?

tia,
What's wrong with

$s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Sep 9 '08 #2
JRough wrote:
I have used this function to create a string called $headers:
[...]
Now I want to unpack the $header array and create two strings,
So, is it a string or an array? Clear your mind.
How to use unpack?
You don't want to use unpack(). It's used to get binary data from
fixed-lenght records, not for this. What you want to do is to *parse* HTML.

--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

You will gain money by an illegal action.

Sep 9 '08 #3
On Sep 9, 2:12*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($fil e_name){
* return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
Date</a></th>

How can I tell if it worked or not? I tried adding these 2 lines and
did not get a value for $s1? The page does work.

$s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';
var_dump $s1;

it is in the else at the end where if the user wants to see the
browser page or if he wants to see it in Excel.
tia,
Janis

---------idle_cars.php-----
include './includes/config.inc.php' ;
include $include_path.' dates.inc.php';
include $include_path." LMS_functions.i nc.php";
#// ############### ############### ############### ##
#// Is the user logged in?
Validate_login( "idle_cars.php? id=".$id);

$days = 3;
$TPL_carnumbers = "<table>";

if(empty($order _by)){
$order_by = 'sighting_date_ asc';
}

# GET CARS FOR GIVEN PARAMETER?
if(empty($id)){
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS";
$file_name = "idle_cars.php? ";
switch ($_SESSION["LMS_USER_D ESC"]){
case 'internal':
$headers = GetLeaseHeaders ($file_name);
$result = SELECT_idle_day s($days,CLM_ord er_by($order_by ));
$lease_row = true;
break;
case 'owner':
$headers = GetLeaseHeaders ($file_name);
$result = SELECT_idle_day s_owner($days,C LM_order_by($or der_by));
$lease_row = true;
break;
case 'customer':
$headers = GetHeaders($fil e_name);
$result = SELECT_idle_day s_customer($day s,CLM_order_by( $order_by));
$lease_row = false;
break;
default:
$headers = GetLeaseHeaders ($file_name);
$result = SELECT_idle_day s($days,CLM_ord er_by($order_by ));
$lease_row = true;
break;
}
}else{
$MSG_carlist = "IDLE CARS - NO MOVEMENT IN 3 DAYS
".GetLeaseCompN ame($id);
$file_name = "idle_cars.php? id=".$id."&";
switch ($_SESSION["LMS_USER_D ESC"]){
case 'internal':
$headers = GetHeaders($fil e_name);
$result = SELECT_idle_day s_lease($id,
$days,CLM_order _by($order_by)) ;
$lease_row = false;
break;
case 'owner':
$headers = GetHeaders($fil e_name);
$result = SELECT_idle_day s_lease_owner($ id,
$days,CLM_order _by($order_by)) ;
$lease_row = false;
break;
default:
$headers = GetHeaders($fil e_name);
$result = SELECT_idle_day s_lease($id,
$days,CLM_order _by($order_by)) ;
$lease_row = false;
break;
}
}
$TPL_carnumbers .= $headers;

if ($_POST['assign']!='Open in Excel'){
if(mysql_numrow s($result)==0){
$TPL_carnumbers .= GetNoCarsMsg($t h);
}else{
while ($row = mysql_fetch_ass oc($result)){
$TPL_carnumbers .=MakeSighting( $lease_row,$row );
}
}

$TPL_carnumbers .="</table>";

include "header.php ";
include $template_path. "template_carli st.html";
include "footer.php ";

}else{
var_dump($resul t);

$s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';

var_dump($s1);
#$data.=makexcl ();
}
include "footer.php ";
Sep 9 '08 #4
On Sep 9, 2:12*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($fil e_name){
* return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
Date</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
* * * * * *<th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= destination'>De stination</a></
th>
* * * * * *<th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
}
Now I want to *unpack the $header array and create two *strings,
called s1 and s2. *I want s1 to be *field names for *excel *ands2 to
be the column names. *For example l_e is the *field name and L_E is
capitalized to be the column header in Excel. *In other words, I want
is the two fields after the order_by= without the 'and the </a>.
How to use unpack?
s1=unpack($head ers/37, 9, $data)
I don't know how to use unpack but I have the $header array as the
string, I counted 37 characters to the word order_by and the word
order_by= is 9 characters I want to grab that word before the '.
How do I make use of the unpack function to get what I want?
tia,

What's wrong with

$s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
Okay, I tested the variable and I did not get nothing. I hit the else
for the Excel button and this is the response to a
print $s1;

string(0) ""
which is empty.

I still need to unpack somehow the string even if I don't use unpack.
Sep 9 '08 #5
On Sep 9, 2:40*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
JRough wrote:
I have used this function to create a string called $headers:
[...]
Now I want to *unpack the $header array and create two *strings,

So, is it a string or an array? Clear your mind.
How to use unpack?

You don't want to use unpack(). It's used to get binary data from
fixed-lenght records, not for this. What you want to do is to *parse* HTML.

--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

You will gain money by an illegal action.
I agree with you. Parse is a better word. So I guess I have to use
string functions then? I'll see if I can and if not
I'll repost the question.

thanks
Sep 9 '08 #6
JRough wrote:
I agree with you. Parse is a better word. So I guess I have to use
string functions then?
No.

Building strings just to parse them down later in the same program is plain
stupid. Refactor your code instead.

--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.9, and PHP
5.2.6-2+b1 generating this signature.
Uptime: 01:26:09 up 19 days, 13:21, 2 users, load average: 0.14, 0.31,
0.34

Sep 9 '08 #7
JRough wrote:
>You don't want to use unpack(). It's used to get binary data from
fixed-lenght records, not for this.

So only numbers can be used with unpack? What do they mean by binary
data? 1's and 0's? When do you use that? I am just curious.
Have you ever, using C, written a record into a file?

--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

Proudly running Debian Linux with 2.6.26-1-amd64 kernel, KDE 3.5.9, and PHP
5.2.6-2+b1 generating this signature.
Uptime: 01:27:36 up 19 days, 13:23, 2 users, load average: 0.28, 0.31,
0.34

Sep 9 '08 #8
On Sep 9, 2:12*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
JRough wrote:
I have used this function to create a string called $headers:
function GetHeaders($fil e_name){
* return "<th><a href='".$file_n ame."&order_by= l_e'>L_E</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= carnumber'>Carn umber</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= location'>Locat ion</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= sighting_date_a sc'>Sighting
Date</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= classification' >Code</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= railroad'>RR</a></th>
* * * * * *<th><a href='".$file_n ame."order_by=o rigin'>Origin</a></th>
* * * * * *<th><a href='".$file_n ame."&order_by= destination'>De stination</a></
th>
* * * * * *<th width='15%'><a href='".$file_n ame."'>ETA</a></th>";
}
Now I want to *unpack the $header array and create two *strings,
called s1 and s2. *I want s1 to be *field names for *excel *ands2 to
be the column names. *For example l_e is the *field name and L_E is
capitalized to be the column header in Excel. *In other words, I want
is the two fields after the order_by= without the 'and the </a>.
How to use unpack?
s1=unpack($head ers/37, 9, $data)
I don't know how to use unpack but I have the $header array as the
string, I counted 37 characters to the word order_by and the word
order_by= is 9 characters I want to grab that word before the '.
How do I make use of the unpack function to get what I want?
tia,

What's wrong with

$s1 = isset($_GET['order_by']) ? $_GET['order_by'] : '';

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===
I do wonder why it doesn't work? If the user clicks an anchor then it
sorts the rows. You would think the $_GET would pick it up
in the url but I suspect the answer to that is the list only prints
in the browser but when you hit the else in the code then
you aren't in the browser anymore you are formatting the query list
for output to excel. Maybe that is the answer.
thanks,
Sep 9 '08 #9
On Sep 9, 2:40*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
JRough wrote:
I have used this function to create a string called $headers:
[...]
Now I want to *unpack the $header array and create two *strings,

So, is it a string or an array? Clear your mind.
How to use unpack?

You don't want to use unpack(). It's used to get binary data from
fixed-lenght records, not for this. What you want to do is to *parse* HTML.

--
----------------------------------
Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

You will gain money by an illegal action.
Maybe I need regexps?
Sep 9 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
13867
by: Geoffrey | last post by:
Hope someone can help. I am trying to read data from a file binary file and then unpack the data into python variables. Some of the data is store like this; xbuffer: '\x00\x00\xb9\x02\x13EXCLUDE_CREDIT_CARD' # the above was printed using repr(xbuffer). # Note that int(0x13) = 19 which is exactly the length of the visible text #
3
3843
by: Andrew Robert | last post by:
Hey everyone, Maybe you can see something I don't. I need to convert a working piece of perl code to python. The perl code is: sub ParseTrig {
0
1730
by: Gary Herron | last post by:
Marlin Rowley wrote: Numpy can do this for you. First, do you really mean the array to contain lists of one string each? If so: kludge here array(, dtype='|S1') array(, ,
19
1878
by: JRough | last post by:
I have used this function to create a string called $headers: function GetHeaders($file_name){ return "<th><a href='".$file_name."&order_by=l_e'>L_E</a></th> <th><a href='". $file_name."&order_by=carnumber'>Carnumber</a></th> <th><a href='". $file_name."&order_by=location'>Location</a></th> <th><a href='". $file_name."&order_by=sighting_date_asc'>Sighting
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.