使用unpack函数获取字段名称 [英] using the unpack function to grab a field name

查看:70
本文介绍了使用unpack函数获取字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用此函数创建了一个名为$ headers的字符串:

函数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''>位置< / a>< / th>

< th>< a href =''"。

$ file_name。"& order_by = sighting_date_asc''>瞄准

日期< / a> < / th>

< th>< a href =''"。

$ file_name。"& order_by = classification''> Code< ; / a>< / th>

< th>< a href =''"。$ file_name。"& order_by = railroad''> RR< / a> < /

th>

< th>< a href =''"。$ file_nam e。order_by = origin> Origin< /

a>< / th>

< th>< a href =''" 。

$ file_name。"& order_by = destination''> Destination< / a>< /

th>

< ; th width ='''15%''>< a href =''"。$ file_name。"''> ETA< / a>< /

th>" ;;


}


现在我要解压缩$ header数组并创建两个字符串,

调用s1和s2。我希望s1是excel的字段名,s2是

是列名。例如,l_e是字段名称,L_E是

,大写为Excel中的列标题。换句话说,我想要

是order_by =之后的两个字段,而不是''和< / a> ;.

如何使用unpack ?


s1 =解包($ header / 37,9,$ data)


我不知道如何使用unpack但是我有$ header数组作为

字符串,我对单词order_by计算了37个字符,单词

order_by =是9个字符我想在之前抓住那个单词''。

我如何利用解包功能来获得我想要的东西?


我忘了提到如果我能做的话会很好它是动态的

而不是硬连线数字因为我有很多这些字符串

与不同的字段名称相同。


tia,

解决方案

标题:


函数GetHeaders(


< blockquote> file_name){

return"< th>< a href =''"。


file_nam e。"& order_by = l_e''> L_E< / a>< / th>

< th>< a href =''"。

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
Date</a></th>
<th><a href=''".
$file_name."&order_by=classification''>Code</a></th>
<th><a href=''".$file_name."&order_by=railroad''>RR</a></
th>
<th><a href=''".$file_name."order_by=origin''>Origin</
a></th>
<th><a href=''".
$file_name."&order_by=destination''>Destination</a></
th>
<th width=''15%''><a href=''".$file_name."''>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($headers/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?

I forgot to mention it would be good if I could make it dynamic
instead of a hardwired number because I have many of these strings
that are the same with different field names.

tia,

解决方案

headers:

function GetHeaders(


file_name){
return "<th><a href=''".


file_name."&order_by=l_e''>L_E</a></th>
<th><a href=''".


这篇关于使用unpack函数获取字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆