473,805 Members | 2,129 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
17 2320
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.
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.
Sep 9 '08 #11
On Sep 9, 4:28*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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
I don't use c for anything. I used c-shell to write a backup
script. okay, thanks it is for writing and reading files or records
so that could be a stored procedure.

I did get more clarity on this string problem. Okay, I have 2
functions that are called to display lists on a page that sort the
rows depending on the header links clicked. The difference in which
function is called depends on which user is logged in. Here is the
outputs, the 2nd header row begins with lease numbers:

L_E Carnumber Location Sighting Date Code RR Origin
Destination ETA

LeaseL_E Carnumber Location Sighting Date Code RR Origin
Destination ETA

All I have to do is "parse" the string so I can output it to excel.
Actually what I need to do is put a "\t" between each word and return
the string.

the $header array has all the anchor tags. I don't need those so I
can't use $headers it has to be parsed.

thanks,

functions:

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>";
}

function GetLeaseHeaders ($file_name){
$lease_header = "<th><a href='".$file_n ame."order_by=l ease'>Lease</
a></th>";
return $lease_header.G etHeaders($file _name);
}
Sep 10 '08 #12
On Sep 9, 4:27*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
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
This is an urgent question under a time limit. I built the string to
output it to the browser which works. All I need to do now is output
it to Excel if the user chooses to and I need the header fields. If
you want to see the page code I can enclose it. I don't see how you
are proposing to do it a different way than to build the first string.
I could really use some help and I don't have time to rewrite anything.
Sep 10 '08 #13
On Sep 9, 4:27*pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
JRough wrote:
I agree with you. *Parse is a better word. *So I guess I have to use
string functions then?

No.
*load average: 0.14, 0.31,
0.34
---code----

$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 ";
print $headers;
}else{

# need code to output header, and data to Excel
$s1 = isset($_GET['order_by'])? $_GET['order_by'] : ''; # gives a ' '
result

}
include "footer.php ";

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>";
}

function GetLeaseHeaders ($file_name){
$lease_header = "<th><a href='".$file_n ame."order_by=l ease'>Lease</
a></th>";
return $lease_header.G etHeaders($file _name);
}

Sep 10 '08 #14
JRough wrote:
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 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($he aders/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...@attg lobal.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,
None of this is in the browser - it all occurs on the server. And if
you are clicking on the link as you indicate, it will be in the $_GET array.

Try print_r($_GET); to see what you get.

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

Sep 10 '08 #15
On Sep 9, 7:54*pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
JRough wrote:
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 *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($hea ders/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,

None of this is in the browser - it all occurs on the server. *And if
you are clicking on the link as you indicate, it will be in the $_GET array.

Try print_r($_GET); to see what you get.
I tried print_r I got a parse error on that line:

Parse error: syntax error, unexpected T_VARIABLE in /home/allrail/
public_html/idle_cars.php on line 101

Does that mean it is working because there is soemthing in the string?
here is that section of code:

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

print_r $s1 ;

#$data.=makexcl ();
}
include "footer.php ";

I don't think I have a typo in it., tnx,
Janis
Sep 10 '08 #16
On 10 Sep, 03:08, JRough <jlro...@yahoo. comwrote:
This is an urgent question under a time limit. *I built the string to
output it to the browser which works. *
Have you thought of employing a programmer?
Sep 10 '08 #17
JRough wrote:
On Sep 9, 4:27 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
escomposlinux.-.punto.-.orgwrote:
>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

This is an urgent question under a time limit. I built the string to
output it to the browser which works. All I need to do now is output
it to Excel if the user chooses to and I need the header fields. If
Have you googled to see what is out there? I did about a year ago and
found a nice class to do the job that works like a charm. It included
headers for the columns. The only drawback I found was that I could
only output one array. I don't have the pointer to where on the net it
is (I copy my own copy now. Use keywords like php export to excel).
You will just have to do your own homework on this one.

you want to see the page code I can enclose it. I don't see how you
are proposing to do it a different way than to build the first string.
I could really use some help and I don't have time to rewrite anything.
Sep 11 '08 #18

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

Similar topics

5
13870
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
3846
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
1732
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
1879
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
9718
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
10614
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10363
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
9186
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
7649
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
6876
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
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3847
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.