How can I handle comments in the middle of an echo command?
This syntax is getting me a syntax error but why is not compliant?
<?
echo "Print this " . /*but not this*/ . " and this\n";
?>
Am I forced to write 3 separate statements?
<?
echo "Print this "
/*but not this*/
echo " and this\n";
?>
Its because it resolves to:
echo "Print this " . . " and this\n";
Which is a syntax error, so is this:
echo "Print this " echo " and this\n";
With the exception of inside string literals, comments effectively don't exist in the code upon execution.
Include the second (or the first) . in the comment:
echo "Print this " . /*but not this .*/ " and this\n";
That will make it resolve to:
echo "Print this " . " and this\n";
Related
I am having trouble getting the URL to display correctly. This works now, but the link has " in front of the url. and yet the url link works fine
echo "<br>" . $result['text'] . " <em>(Contributed by: \"<a
href=\"http://example.com/portfolio?ID=$result[ID]\">" .
$result['display_name'] . "</a>" . ")</em>" . "<br>";
sigh:
echo '<br>' . $result['text'] . ' <em>(Contributed by: <a
href="http://example.come/portfolio?ID="'.$result['ID'].'">'.
$result['display_name'] .'</a>)</em><br>';
I am trying to loop through my mysql query result and print out some of the data. What I expected was when I added "\n" to the end of the print message, it would print each message on a separate line. But for some reason its all on one line. Why is this and how can I make each message be on a separate line?
while($row = mysql_fetch_array($result))
{
$message = $row['action_type'] . " " . $row['identifier'] . " # " . " placeholder ";
if($row['location'] !== NULL)
{
$message += " on " . $row['location'] . "\n";
}
echo $message . "\n";
}
Your $message variable is ending with a /n when it should be \n. Try updating it to fix (unless of course, in that section of the code it's on purpose):
$message += " on " . $row['location'] . "\n";
The actual echo statement ends with a real newline, so this should work properly in a command-line, but not in a browser.
To get it to display on a new line in a browser, change the \n instances to <br />:
echo $message . "<br />";
I have a huge list of stuff for a glossary ( about 17 pages worth ) that I have to put into an XML file. So I decided I'd use php to make it. My code works, except where ALL the XML code is, it doesn't show because it's trying to render it. Help?
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
I assume by render it you mean in your browser? If so, you'll need to escape the characters so they will be interpreted literally rather than as markup.
Check out htmlspecialchars and htmlentities
use CDATA construction:
echo "<desc><![CDATA[" . $arg[$i] . " - " . $arg[$i+2] . "]]></desc>";
If this is your entire script, fastest way would probably be to swap all of the <'s with <
$arg=explode("\n", $strang);
echo count($arg);
for ($i=0;$i<=count($arg);$i=$i+3)
{
echo "<word id='" . $arg[$i+1] . "'>";
echo "<desc>" . $arg[$i] . " - " . $arg[$i+2] . "</desc>";
echo "<pic></pic>";
echo "<audio></audio>";
}
I have a mySQL table loaded with 50 rows. Each row has the necessary information to process a credit card. When the user clicks on Process Credit Cards, query the table and display each row on the page using html. Once the data has been displayed on the page a scrip would begin to process each row through the merchant account and turn the corresponding row either red for decline or green for approve without refreshing the page after each transaction. I think I need to use AJAX or jQuery to make this happen but I'm not sure I'm headed in the right direction. Here is the script to process the transactions:
<?php
$request = new GatewayRequest();
$response = new GatewayResponse();
$service = new GatewayService();
$request->Set(GatewayRequest::MERCHANT_ID(), "111111111111111");
$request->Set(GatewayRequest::MERCHANT_PASSWORD(), "xxxxxxxxxxxx");
$time = time();
$request->Set(GatewayRequest::MERCHANT_CUSTOMER_ID(), $time . '.PHPTest');
$request->Set(GatewayRequest::MERCHANT_INVOICE_ID(), $time . '.SaleTest');
$request->Set(GatewayRequest::AMOUNT(), "9.99");
$request->Set(GatewayRequest::CARDNO(), "4111111111111111");
$request->Set(GatewayRequest::EXPIRE_MONTH(), "02");
$request->Set(GatewayRequest::EXPIRE_YEAR(), "2010");
$request->Set(GatewayRequest::CVV2(), "999");
$request->Set(GatewayRequest::CUSTOMER_FIRSTNAME(), "Joe");
$request->Set(GatewayRequest::CUSTOMER_LASTNAME(), "PHPTester");
$request->Set(GatewayRequest::EMAIL(), "phptest#fakedomain.com");
$request->Set(GatewayRequest::IPADDRESS(), $_SERVER['REMOTE_ADDR']);
$request->Set(GatewayRequest::BILLING_ADDRESS(), "123 Main St");
$request->Set(GatewayRequest::BILLING_CITY(), "Las Vegas");
$request->Set(GatewayRequest::BILLING_STATE(), "NV");
$request->Set(GatewayRequest::BILLING_ZIPCODE(), "89141");
$request->Set(GatewayRequest::BILLING_COUNTRY(), "US");
$request->Set(GatewayRequest::SCRUB(), "IGNORE");
$request->Set(GatewayRequest::CVV2_CHECK(), "IGNORE");
$request->Set(GatewayRequest::AVS_CHECK(), "IGNORE");
$service->SetTestMode(TRUE);
if ($service->PerformPurchase($request, $response)) {
print "Purchase succeeded\n";
print "Response Code: " .
$response->Get(GatewayResponse::RESPONSE_CODE()) . "\n";
print "Reasone Code: " .
$response->Get(GatewayResponse::REASON_CODE()) . "\n";
print "Auth No: " . $response->Get(GatewayResponse::AUTH_NO()) . "\n";
print "AVS: " . $response->Get(GatewayResponse::AVS_RESPONSE()) . "\n";
print "CVV2: " . $response->Get(GatewayResponse::CVV2_CODE()) . "\n";
print "GUID: " . $response->Get(GatewayResponse::TRANSACT_ID()) . "\n";
print "Account: " .
$response->Get(GatewayResponse::MERCHANT_ACCOUNT()) . "\n";
print "Scrub: " .
$response->Get(GatewayResponse::SCRUB_RESULTS()) . "\n";
} else {
print "Purchase failed\n";
print "GUID: " . $response->Get(GatewayResponse::TRANSACT_ID()) . "\n";
print "Response Code: " .
$response->Get(GatewayResponse::RESPONSE_CODE()) . "\n";
print "Reasone Code: " .
$response->Get(GatewayResponse::REASON_CODE()) . "\n";
print "Exception: " .
$response->Get(GatewayResponse::EXCEPTION()) . "\n";
print "Scrub: " .
$response->Get(GatewayResponse::SCRUB_RESULTS()) . "\n";
}
?>
Will this type of code work with AJAX or jQuery without being rewritten? Any help would be appreciated.
Anything can be made to work without being rewritten, but you've set yourself up for a lot of headaches there. You'll probably have much better luck (and save yourself tons of time) by formatting all those print statements into an array and JSON encoding it. Obviously javascript loves JSON.
So i installed XMAPP to view my php site im developing for a php mysql class at my local college and I ran aground hours ago and have been searching frantically for answers since. whenever i try to view my site all i see is this
" . $row['tid'] . ""; echo $id; $thisName = "\n
" . $row['fname'] . " " . $row['lname'] ."
"; echo $thisName; $description = "\n
" . nl2br($row['description']) . "
"; echo $description; echo ""; } include ("footer.php"); ?>
or something similar. we host on a local server that has everything we need but cannot access it from our homes. I was wondering if anyone could lend me a hand?
It looks like you have an echo statement where you're using a single quote to open a string but not close it. For instance:
echo '" . $row['tid'] . ""; echo $id; $thisName = "
Go search in your source for something like this. I'd bet that this is your error.