What's the error in concatenation in below code? [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What's the error in below code:
I'm getting the error as below:
PHP Parse error: syntax error, unexpected T_STRING in pdf_test_question_paper.php on line 38
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/".$coaching_details['coach_inst_logo_name']." width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Exam Easing your Exam Preparation</h2>
<span>$coaching_address</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';
Any help would be greatly appreciated.

When you wrap your string in single quotes, you're using literal values. That means $coaching_address will never be evaluated. You should use a heredoc instead for this amount of code:
$header_html = <<<EOD
<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.xyz.com/upload_media/coaching/logo/display/$coaching_details['coach_inst_logo_name']" width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Zimma Exam Easing your Exam Preparation</h2>
<span>$coaching_address</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>
EOD;

please use the correct quotation in case of string concaternation:
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
<span>'.$coaching_address.'</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';

You start your string using single quotes, however you are trying to break out of the quotes using a double quote.
The correct code is:
$header_html = '<table border="0" width="100%" cellpadding="0" cellspacing="0" style="font-size:12px; font-family:verdana;">
<tr>
<td><img src="http://www.example.com/upload_media/coaching/logo/display/'.$coaching_details['coach_inst_logo_name'].' width="198"></td>
<td>
<h2 style="margin:0;padding:0;">Jumbo Easing your Exam Preparation</h2>
<span>'.$coaching_address.'</span>
</td>
</tr>
<tr><td colspan="2"><hr style="background-color: #000000;height:1px;border:1px;"/></td></tr>
</table>';

Related

html table right aligned has invisible part on the left of screen

I have a html table. Its right aligned. I have a table within it with fields. But when my chrome browser displays the table some portion of table (leftmost) is cropped in the left, ie its leftmost contents are outside of the screen.
The image of how my table looks like is here: https://yadi.sk/i/rR6rm8nuZsfXlA
How to make the right-aligned table to start at the beginning of the screen (on the left side) to see full table contents?
my code is:
<table width=600 border="0" align="right" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1">
<?php echo $rows2['a_id']; ?>
</td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1">
<?php echo $rows2['a_name']; ?>
</td>
</tr>
Aligning a table to right has no meaning if your table width is bigger than screen width. You can try adding this to
<style>
#media only screen and (min-width: 600px) {
.mytable {
margin-right: 0px;
margin-left: auto
}
}
</style>
Assign the my table class to the table you want to align right and remove align=right from html.
Just remove the margin on the side and you can also use a percetage value for the auto resize of the table on screen narrowing
It looks like the width of your outer table (600) does not fill the available space on your web page. If you want the table to start at the beginning of the screen, you could try removing the right alignment like this:
<table width=600 border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#F8F7F1"><strong>ID</strong></td>
<td bgcolor="#F8F7F1">:</td>
<td bgcolor="#F8F7F1"><?php echo $rows2['a_id']; ?></td>
</tr>
<tr>
<td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
<td width="5%" bgcolor="#F8F7F1">:</td>
<td width="77%" bgcolor="#F8F7F1"><?php echo $rows2['a_name']; ?></td>
</tr>
</table>
</td>
</tr>
</table>

HTML Purifier for webmail

I'm working on small webmail client. For safely embedding html I want to use HTML Purifier (BTW: it's a good idea?).
I checked it with several emails and some problems. One email (from Google) is having something like this:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="4%">
<td width="92%" style="padding-top:18px; padding-bottom:10px; opacity:0.7">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<td width="30%">
<img style="display:inline-block;" height="26" src="https://www.gstatic.com/local/guides/email/images/photo-impact/googlelogo_light_clr-f040d5d9.png">
<td>
<td width="70%" style="text-align:right">
</td>
</tbody>
</table>
Converts to:
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%">
</td><td width="92%" style="padding-top:18px;padding-bottom:10px;opacity:.7;">
</td><td width="30%">
<img style="display:inline-block;" height="26" src="https://www.gstatic.com/local/guides/email/images/photo-impact/googlelogo_light_clr-f040d5d9.png" alt="googlelogo_light_clr-f040d5d9.png">
</td><td>
</td><td width="70%" style="text-align:right;">
</td>
</tr></table>
I don't know why it remove second <table> tag (also it close wrong <td> and removes <tbody>). Is it possible to change HTML Purifier to make it work for those situations?

PHP DOM get element which contains

Need help with parsing HTML code by PHP DOM.
This is simple part of huge HTML code:
<table width="100%" border="0" align="center" cellspacing="3" cellpadding="0" bgcolor='#ffffff'>
<tr>
<td align="left" valign="top" width="20%">
<span class="tl">Obchodne meno:</span>
</td>
<td align="left" width="80%">
<table width="100%" border="0">
<tr>
<td width="67%">
<span class='ra'>STORE BUSSINES</span>
</td>
<td width="33%" valign='top'>
<span class='ra'>(od: 02.10.2012)</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
What I need is to get text "STORE BUSINESS". Unfortunately, the only thing I can catch is "Obchodne meno" as a content of first tag, so according to this content I need to get its parent->parent->first sibling->child->child->child->child->content. I have limited experience with parsing html in php so any help will be valuable. Thanks in advance!
Make use of DOMDocument Class and loop through the <span> tags and put them in array.
<?php
$html=<<<XCOE
<table width="100%" border="0" align="center" cellspacing="3" cellpadding="0" bgcolor='#ffffff'>
<tr>
<td align="left" valign="top" width="20%">
<span class="tl">Obchodne meno:</span>
</td>
<td align="left" width="80%">
<table width="100%" border="0">
<tr>
<td width="67%">
<span class='ra'>STORE BUSSINES</span>
</td>
<td width="33%" valign='top'>
<span class='ra'>(od: 02.10.2012)</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
XCOE;
$dom = new DOMDocument;
$dom->loadHTML($html);
foreach ($dom->getElementsByTagName('span') as $tag) {
$spanarr[]=$tag->nodeValue;
}
echo $spanarr[1]; //"prints" STORE BUSINESS

Pull data from a webpage to use [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
To give some background, I sell Lego parts online. The order total when you place the order is based on the price of the parts you purchased, and the shipping costs.
Shipping costs vary depending on the weight of the order, and the country of shipment.
I am not a techie buff, and thats why I need some help. I know the basics, but not much else, though I'd love to learn and I've been trying around with this for days before coming here.
The source code of an order page, the only place where you can see the weight is this:
<FONT CLASS="fv">Estimated Weight of Order:</FONT></TD><TD ALIGN="RIGHT"><FONT CLASS="fv">2.17oz 61.44g</FONT>
It is the same for every single order.
So, I know where the data I want is.
What I need help with is, coding something that pulls the data out of this webpage (say it's inside a webpage called order.com/order.asp and the document contains a bunch of other data apart from the weight) and exporting a shipping price based on the weight it inputed. I don't know whether you can do this with PHP or Python, etc.
I would have on my server a... say a table with the shipping costs based on weight. Now, what I needed, would be to take that bit of data from the order.com website into my own server. (On my own server process the weight data that I took, match it with the shipping cost, pull out invoices, etc). The weight data is in the order page, always on a line like the one I posted on the question. I just read about web scraping. Maybe some PHP that looks into the order page till it finds the line with the weight, and pulls out the weight?
Many, many, many thanks for your help, and I apologize in advance if I sound too uninformed, which I am. I really need a detailed explanation.
Gerald
*TL;DR*Two webpages. One is in my server and one isn't. The one that isn't in my server (order.asp), has this line:
<FONT CLASS="fv">Estimated Weight of Order:</FONT></TD><TD ALIGN="RIGHT"><FONT CLASS="fv">XX.XXoz XX.XXg</FONT>
I need something that I can put in my server, queries the weight from the page that isn't on my server (order.asp page) and matches the weight with a shipping price that I would have on my page (as a table or maybe with ifs).
There will be different order pages (order1.asp order2.asp order3.asp) with different weights. The script or whatever should do that for ea. wpage.
Thanks.
This would be the source code of an example page that I would need to take the weight of. Removed some sensitive info.
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
function killImage(imgName){
if (document.images){
document.images[imgName].src="/images/noImage.gif"
}
}
function killImageM(imgName){
if (document.images){
document.images[imgName].src="/images/noImageM.gif"
}
}
</SCRIPT>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
<META HTTP-EQUIV="IMAGETOOLBAR" CONTENT="NO">
<LINK REL="STYLESHEET" TYPE="text/css" HREF="/stylesheet.css?13">
<STYLE TYPE="text/css">body { margin: 15 auto; }</STYLE>
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript" SRC="/js/getAjax.js"></SCRIPT>
<SCRIPT TYPE="text/javascript" LANGUAGE="javascript" SRC="/lytebox/lytebox.js?10"></SCRIPT>
<LINK REL="STYLESHEET" HREF="/lytebox/lytebox.css?13" TYPE="text/css" MEDIA="screen" />
</HEAD>
<BODY BGCOLOR="#666666">
<CENTER>
<TABLE WIDTH="680" CELLPADDING="10" CELLSPACING="0"><TR><TD BGCOLOR="#FFFFFF">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0"><TR>
<TD><IMG SRC="/images/logowhite.gif" WIDTH="200" HEIGHT="60" ALIGN="ABSMIDDLE" BORDER="0"> </TD>
<TD> <FONT SIZE="+3">Order #3953198</FONT></TD></TR></TABLE><P><FONT FACE="Tahoma,Arial" SIZE="2">
<HR NOSHADE SIZE="1" COLOR="#000000"><B>Order Summary</B><HR NOSHADE SIZE="1" COLOR="#000000">
<TABLE WIDTH="100%" CELLPADDING="5" CELLSPACING="0" BORDER="0" BGCOLOR="#EEEEEE"><TR><TD WIDTH="60%" VALIGN="TOP">
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0" CLASS="ta">
<TR>
<TD WIDTH="125">Order Date:</TD>
<TD>Nov 20, 2013 17:12</TD>
</TR>
<TR>
<TD>Payment By:</TD>
<TD>PayPal.com</TD>
</TR>
<TR>
<TD>Payment In:</TD>
<TD>Euro</TD>
</TR>
<TR VALIGN="TOP">
<TD>Order Status:</TD>
<TD>Shipped</TD>
</TR>
<TR>
<TD>Changed:</TD>
<TD>Nov 22, 2013 14:15</TD>
</TR>
<TR>
<TD NOWRAP>Total Items:</TD>
<TD>24</TD>
</TR>
<TR>
<TD NOWRAP>Unique Items (Lots):</TD>
<TD>2</TD>
</TR>
<TR>
<TD NOWRAP>Invoiced:</TD>
<TD>Nov 21, 2013 08:56</TD>
</TR>
<TR VALIGN="TOP">
<TD NOWRAP>Shipping Method:</TD>
<TD>Registered<BR><FONT CLASS="fv">By default, with tracking number and insured up to 30 euros only.</FONT></TD>
</TR>
</TABLE>
</TD><TD WIDTH="40%" VALIGN="TOP">
<TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0" CLASS="ta">
<TR>
<TD>Order Total:</TD>
<TD ALIGN="RIGHT">EUR 8.92</TD>
</TR>
<TR>
<TD>Shipping:</TD>
<TD ALIGN="RIGHT">EUR 4.85</TD>
</TR>
<TR>
<TD>Insurance:</TD>
<TD ALIGN="RIGHT">EUR 0.00</TD>
</TR>
<TR>
<TD>Additional Charges 1:</TD>
<TD ALIGN="RIGHT">EUR 0.00</TD>
</TR>
<TR>
<TD>Additional Charges 2:</TD>
<TD ALIGN="RIGHT">EUR 0.00</TD>
</TR>
<TR>
<TD>Credit:</TD>
<TD ALIGN="RIGHT">EUR 0.00</TD>
</TR>
<TR>
<TD>Grand Total:</TD>
<TD ALIGN="RIGHT"><B>EUR 13.77</TD>
</TR>
<TR>
<TD>Orders in this Store:</TD>
<TD ALIGN="RIGHT">1</TD>
</TR>
</TABLE>
</TD></TR>
</TABLE><HR NOSHADE SIZE="1" COLOR="#000000"><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%" CLASS="ta"><TR><TD><B>Items in Order</B></TD></TR></TABLE><HR NOSHADE SIZE="1" COLOR="#000000"><TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="3" CLASS="ta"><TR BGCOLOR="#C0C0C0"><TD><B>Image</B></TD><TD ALIGN="CENTER"><B>Condition</B></TD><TD><B>Item Description</B></TD><TD ALIGN="RIGHT"><B>Lots</B></TD><TD ALIGN="RIGHT"><B>Qty</B></TD><TD ALIGN="RIGHT"><B>Left</B></TD><TD ALIGN="RIGHT"><B>Price</B></TD><TD ALIGN="RIGHT"><B>Total</B></TD><TD ALIGN="RIGHT"><B>Weight</B></TD></TR><TR><TD COLSPAN="2" BGCOLOR="#C0C0C0"><B>Batch #1</B></TD><TD COLSPAN="7" BGCOLOR="#C0C0C0"><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"><TR><TD><FONT CLASS="fv">Submitted on Nov 20, 2013 17:12</TD><TD ALIGN="RIGHT"><IMG SRC="/images/printer16.png" WIDTH="16" HEIGHT="16" BORDER="0" ALT="Print Batch" TITLE="Print Batch"><IMG SRC="/images/dot.gif" WIDTH="5" HEIGHT="1"><IMG SRC="/images/invoice16YC.gif" WIDTH="16" HEIGHT="16" ALT="Batch Invoiced" TITLE="Batch Invoiced"></TD></TR></TABLE></TD></TR><TR BGCOLOR="FFFFFF"><TD HEIGHT="60"><CENTER><A ID='imgLink0' HREF='/catalogItemPic.asp?P=60208' REL='blcatimg'><IMG ALT="Lot ID: 48295541 Part No: 60208 Name: Wheel 31mm D. x 15mm Technic" TITLE="Lot ID: 48295541 Part No: 60208 Name: Wheel 31mm D. x 15mm Technic" BORDER='0' WIDTH='80' HEIGHT='60' SRC='http://img.bricklink.com/P/86/60208.gif' NAME='img0' ID='img0' onError="killImage('img0');"></A><BR><FONT FACE='Tahoma,Arial' SIZE='1'>*</FONT></TD><TD ALIGN="CENTER"><B>New</B></TD><TD><SPAN CLASS="u"><FONT COLOR="#000000">Light Bluish Gray Wheel 31mm D. x 15mm Technic </FONT></SPAN><BR><FONT CLASS="fv">AB4</FONT></TD><TD ALIGN="RIGHT"> </TD><TD ALIGN="RIGHT">12</TD><TD ALIGN="RIGHT">X</TD><TD ALIGN="RIGHT">EUR 0.11</TD><TD ALIGN="RIGHT">EUR 1.32</TD><TD ALIGN="RIGHT"><FONT CLASS="fv">38.16g</TD></TR><TR BGCOLOR="EEEEEE"><TD HEIGHT="60"><CENTER><A ID='imgLink1' HREF='/catalogItemPic.asp?P=6179' REL='blcatimg'><IMG ALT="Lot ID: 49014568 Part No: 6179 Name: Tile, Modified 4 x 4 with Studs on Edge" TITLE="Lot ID: 49014568 Part No: 6179 Name: Tile, Modified 4 x 4 with Studs on Edge" BORDER='0' WIDTH='80' HEIGHT='60' SRC='http://img.bricklink.com/P/86/6179.gif' NAME='img1' ID='img1' onError="killImage('img1');"></A><BR><FONT FACE='Tahoma,Arial' SIZE='1'>*</FONT></TD><TD ALIGN="CENTER"><B>New</B></TD><TD><SPAN CLASS="u"><FONT COLOR="#000000">Light Bluish Gray Tile, Modified 4 x 4 with Studs on Edge </FONT></SPAN><BR><FONT CLASS="fv">AJ2</FONT></TD><TD ALIGN="RIGHT"> </TD><TD ALIGN="RIGHT">12</TD><TD ALIGN="RIGHT">X</TD><TD ALIGN="RIGHT">EUR 0.633</TD><TD ALIGN="RIGHT">EUR 7.596</TD><TD ALIGN="RIGHT"><FONT CLASS="fv">23.28g</TD></TR><TR BGCOLOR="#DDDDDD"><TD COLSPAN="3"><B>Batch Total:</B></TD><TD ALIGN="RIGHT">2</TD><TD ALIGN="RIGHT">24</TD><TD></TD><TD> </TD><TD ALIGN="RIGHT">EUR 8.92</TD><TD ALIGN="RIGHT"><FONT CLASS="fv">61.44g</TD></TR><TR BGCOLOR="#C0C0C0"><TD COLSPAN="3"><B>Order Total:</B></TD><TD ALIGN="RIGHT">2</TD><TD ALIGN="RIGHT">24</TD><TD></TD><TD> </TD><TD ALIGN="RIGHT">EUR 8.92</TD><TD ALIGN="RIGHT"></TD></TR><TR><TD COLSPAN="10" ALIGN="RIGHT" BGCOLOR="#EEEEEE"><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%"><TR><TD><FONT CLASS="fv">Estimated Weight of Order:</FONT></TD><TD ALIGN="RIGHT"><FONT CLASS="fv">2.17oz 61.44g</FONT></TD></TR></TABLE></TD></TR></TABLE><TABLE WIDTH="100%" BORDER="0" CELLPADDING="1" CELLSPACING="0" CLASS="ta"><TR><TD COLSPAN="2" CLASS="fv" ALIGN="RIGHT">Contact your buyer about this order<BR> </TD></TR></TABLE><HR NOSHADE SIZE="1" COLOR="#000000"><FONT CLASS="fv"><CENTER>This order will be purged from the BrickLink website on May 20, 2014.</CENTER></FONT></TABLE><FONT CLASS="fv"><P><CENTER><FONT COLOR="#FFFFFF">Back to Orders</FONT> | <FONT COLOR="#FFFFFF">Show Temporary Checkboxes</FONT> | <FONT COLOR="#FFFFFF">Show Categories</FONT> | <FONT COLOR="#FFFFFF">Consolidate Batches</FONT> | <FONT COLOR="#FFFFFF">My Settings</FONT><P><FONT COLOR="#FFFFFF">Hide Qty Left in My Inventory</FONT> | <FONT COLOR="#FFFFFF">Hide Item Weight</FONT> | <FONT COLOR="#FFFFFF">Show My Cost</FONT> | <FONT COLOR="#FFFFFF">Show Only Items in Order</FONT> | <FONT COLOR="#FFFFFF">Edit Order</FONT>
It's a little tough to write full-blown code without looking at the page you wish to scrape, but you should be able to use the following code to get what you want. The code below reads in a file called "html.txt", finds all orders in that text file, finds the total weight values in ozs and grams, and writes that data to an output file called foundWeights.txt. To run the code, just save your html in a text file called "html.txt", save the code below in a file called "findweights.py", and then put both of those files in the same folder. Then, open a shell or a terminal window, navigate to that folder, and type "python findweights.py" and momentarily a text file will appear in the same folder with your data in it.
html = open("html.txt").read()
out = open("foundWeights.txt", "w")
#split html on order number
legoOrders = html.split("Order #")
for order in legoOrders[1:]:
print order
orderNumber = order.split("<")[0]
weightString = order.split('Estimated Weight of Order:</FONT></TD><TD ALIGN="RIGHT"><FONT CLASS="fv">')[1]
splitWeightString = weightString.split(' ')
splitStringFinal = splitWeightString[1].split("<")
grams = splitStringFinal[0]
ozs = weightString.split('&nbsp')[0]
out.write(str(orderNumber) + "\t" + str(grams) + "\t" + str(ozs) + "\n"
Outfile is tab-separated (Order #, grams, ozs):
3953198 61.44g 2.17oz

modify a <DIV> element with CURL

I know how to provide or modify a field with CURL curl_setopt function and to work with cookies, but what I could not find is how to modify an HTML element with CURL.
For instance, let's say I want to replace the function "submit_device_form" in below code
<div id="bottombuttons">
<table border="0" cellspacing="0" cellpadding="0" style="width:100%;">
<!-- buttons -->
<tr>
<td> </td>
<td class="separatorButton">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Set</td>
<td>Cancel</td>
</tr>
</table>
</td>
</tr>
<!-- fixes the width of the first column -->
<tr>
<td style="padding:0;"><img src="images/spacer.gif" alt="" width="200" height="1" border="0" ></td>
<td style="padding:0;"><img src="images/spacer.gif" alt="" width="360" height="1" border="0" ></td>
</tr>
</table>
</div>
with "submit_MY_form", a new JavaScript function included in my PHP script. How would I go for it?
I looked into the "PHP Simple HTML DOM Parser" library since it provides the setAttribute and removeAttribute functions that would allow me to do that easily, but then I miss the info on how to give it access to the page read wia CURL, so I'm stuck.
Thanks for your help,
Robert

Categories