Shortened snippet when getting XML output using PHP

6 views
Skip to first unread message

李傑

unread,
Jan 4, 2015, 11:35:28 PM1/4/15
to Google-Search-...@googlegroups.com
Hi all,

I am using GSA 7.2.0.G.252. 

I found that the snippet of some results in the XML output from PHP program is shorter than that from browser.

For example, I run this query in browser:
and I got this snippet:

<S>&lt;b&gt;...&lt;/b&gt; 15 The Hinge Factor Erik Durschmied 16 How to Make the Impossible Possible&lt;br&gt; Anthony, Robert 17 If the World Were a Village of 100 People Kayoko Ikeda,&lt;br&gt; Douglas Lummis 18 In Search of Respect : Selling &lt;b&gt;Crack&lt;/b&gt; in El &lt;b&gt;...&lt;/b&gt;  </S>


While I use a PHP program:


I got this shortened snippet:

<S>&lt;b&gt;...&lt;/b&gt; Anthony, Robert 17 If the World Were a Village of 100 People Kayoko Ikeda,&lt;br&gt; Douglas Lummis 18 In Search of Respect : Selling &lt;b&gt;Crack&lt;/b&gt; in El Barrio &lt;b&gt;...&lt;/b&gt;  </S>


How can I get the same snippet?

Thanks, 
Kit

Dave Watts

unread,
Jan 5, 2015, 2:53:38 PM1/5/15
to Google-Search-...@googlegroups.com
> I found that the snippet of some results in the XML output from PHP program
> is shorter than that from browser.

My guess is that PHP is truncating this. You might use a recording
proxy/packet sniffer to see what's actually being returned by the GSA.

Dave Watts, CTO, Fig Leaf Software
1-202-527-9569
http://www.figleaf.com/
http://training.figleaf.com/

Fig Leaf Software is a Service-Disabled Veteran-Owned Small Business
(SDVOSB) on GSA Schedule, and provides the highest caliber vendor-
authorized instruction at our training centers, online, or onsite.

李傑

unread,
Jan 9, 2015, 3:03:47 AM1/9/15
to Google-Search-...@googlegroups.com
Having compared the output XML from the PHP and Browser, there is a difference in the value of "ulang" tag.

browser xml:
<PARAM name="ulang" value="zh-TW" original_value="
zh-TW"/>

php  xml:
<PARAM name="ulang" value="" original_value=""/>

According to GSA Search Protocol Reference :
"ulang: Gets the user's browser language. The user can specify this search parameter. If it is not specified, it takes the value from HTTP headers in the received search request. XSLT uses this parameter to translate titles and snippets into the user's browser language."

So, I tried specifying the ulang=zh-TW in the query:

$test_result
= file_get_contents($test_url);
file_put_contents
("test_result.xml", $test_result);

But the ulang remains empty in the output XML.
<PARAM name="ulang" value="" original_value=""/>

Then, I changed my browser's language setting to "en" and run the query in the browser:
This time, the snippet matched that from the PHP. So I believe the PHP program works like a browser with language setting as "en".

So, how can I specify the search parameter "ulang" in the PHP program?

Thanks.



Mathias Bierl

unread,
Jan 9, 2015, 7:10:54 AM1/9/15
to Google-Search-...@googlegroups.com
Set the language in your PHP Script in the HTTP Header for your request (Accept-Language)

李傑

unread,
Jan 14, 2015, 2:58:37 AM1/14/15
to Google-Search-...@googlegroups.com
Hi Mathias,

We have adjusted our PHP code to send the header "Accept-Language" additionally and it works. The result snippets are identical now. Thanks.

Rgds,
Kit
Reply all
Reply to author
Forward
0 new messages