I'm using fwrite() to write a file, however, every time it runs, it prints all of the information to the webpage it's on and writes to the file, too. I'd rather it not echo it to the page.
Alright, I've retrieved the code. Here it is:
fwrite($data_file, "Confirmation Data: \r\n\r\n Song: " . $input_song . "\r\nFile1: " . $file_var1 . "\r\nFile2: " . $file_var2 . "\r\nFile3: " . $file_var3 . "\r\nFile4: " . $file_var4 . "\r\nExplanation Text: " . $input_explanation);
Whenever I run this, it outputs everything in the second place of fwrite() onto the page, so it outputs the follow onto the page, except with the variables replaced for their values:
Confirmation Data: \r\n\r\n Song: " . $input_song . "\r\nFile1: " . $file_var1 . "\r\nFile2: " . $file_var2 . "\r\nFile3: " . $file_var3 . "\r\nFile4: " . $file_var4 . "\r\nExplanation Text: " . $input_explanation
You should post your code, so we can follow it but most probably you are also echoing out the code as HTML in your PHP file and this is why it prints out on the screen.
You said your information is being echoed and not written to file. Perhaps you are using echo instead of using file related functions. However, without access to your code, I can only post how to write information to a file in PHP:
<?php
error_reporting(E_ALL);//display all errors
ini_set('display_errors', true);
$filename = "testfile.txt";//the name of your output file
$fh = fopen($myFile, 'w');//create a filehandler - fh) and open the file in write mode
$string = "ABCDEFGH\n";//test string to write to the file
$myvar = fwrite($fh, $string);
$string = "IJKLMNO\n";//update the string variable with new data
fwrite($fh, $string);//write more data - can be repeated ad -infinitum
fclose($fh);//finally, close the file
But, if you truly want definitive answers, post your code so that we may be able to help you.
Related
I am having an issue when I try to post the Join Date on my web page:
Fatal error: Class 'getJoinDate' not found in ********
$newDate = getJoinDate::createFromFormat("l dS F Y", $dateFromDB);
$posts = PostQuery::create()->findPk(1);
echo "<p>", "ID:".$posts->getUserID().", ".$posts->getContent().", ".$posts->getJoinDate()." </p>";'
Please let me know what I must do to display the format.
It's this code:
echo "<p>", "ID:".$posts->getUserID().", ".$posts->getContent().", ".$posts->getJoinDate()." </p>";'
I'm not sure what your commas were supposed to be, but I guess not actual commas and so you have commas where stops should be: echo "<p>", <--
And an apostrophe at the end of the line: </p>";'<--
You should grab a decent IDE that will show errors like this immediately, saves a lot of time. And read your error log as it tells you such errors.
Using double quotes variable names will be expanded, try this:
echo "<p>ID: {$posts->getUserID()} {$posts->getContent()} {$posts->getJoinDate()}</p>";
Or this way:
echo '<p>ID: ' . $posts->getUserID() . ' ' . $posts->getContent() . ' ' . $posts->getJoinDate() . '</p>';
This is my current code:
$parcels = $api->parcels->get();
$url = (array_values($parcels)[0]['label']['label_printer']);
$goToUrl = $api->getUrl($url);
$goToUrl = str_replace('/api/v2//api/v2/', '/api/v2/', $goToUrl);
print_r($goToUrl);
echo "<br />";
echo $url;
Why do I use str_replace()? because I am intending to redirect to $goToUrl and this is not working because the current API is giving me the link wrong.
This is my output:
https://api_key:api_secret#panel.sendcloud.nl/api/v2/labels/label_printer/1369315
Code where it's used in the email:
$email_body = ("This is Label: " . ($parcel_name) . " |OrderId: " . ($parcel_order_number) . "\n\n See Label: " . $goToUrl );
Current situation this url get's emailed, and in the mail I would like it to be a clickable link instead of the entire url. Even only maybe the last part is good enough:
label/label_printer/1369315
i've seen preg_replace but never used it before so I find it very difficult to understand it.
To enable HTML in phpmailer you have to use
$mailer->isHtml(true); //Enables html in the regular body.
Or
$mailer->MsgHTML($body); //Enables and SETS the message body with HTML.
You can see http://phpmailer.worxware.com/ for examples / guides on how to use phpmailer with html / configure it properly.
I'm trying to combine several php files in to one larger with php.
I'm sending form data to a small files and use includes to load into them in a
main page.
With many of these files each time I work an inspection project is getting to be a little time consuming dropping to a command prompt.
I'm able to combine pages with a command prompt using the "cat" command and pull the ones not yet completed.
cat page-1.php page-2.php page-3.php page-4.php page-5.php page-6.php page-7.php page-8.php page-9.php page-10.php page-11.php page-12.php >> newpage.php
I need help with php to perform this with out having to execute a shell command from php.
I also need the code to ignore missing files and continue with the rest.
Thanks in advance
foreach (glob("*.php") as $filename) {
$code.=file_get_contents("./$filename");
}
file_put_contents("./combined.php",$code);
Run that in your target directory. That reads all your php files in the directory, extracts their code and then combines and saves it in your new file.
This will keep them in the order they need to be. The other way does not keep them in order and will display errors.
<?php
$txt1 = file_get_contents('page-001.php');
$txt1 .= "\n" . file_get_contents('page-002.php');
$txt1 .= "\n" . file_get_contents('page-003.php');
$txt1 .= "\n" . file_get_contents('page-004.php');
$txt1 .= "\n" . file_get_contents('page-005.php');
$txt1 .= "\n" . file_get_contents('page-006.php');
$txt1 .= "\n" . file_get_contents('page-007.php');
$txt1 .= "\n" . file_get_contents('page-008.php');
$txt1 .= "\n" . file_get_contents('page-009.php');
$txt1 .= "\n" . file_get_contents('page-010.php');
$txt1 .= "\n" . file_get_contents('page-011.php');
$txt1 .= "\n" . file_get_contents('page-012.php');
$fp = fopen('newcombined.php', 'w');
if(!$fp)
die('Could not create / open text file for writing.');
if(fwrite($fp, $txt1) === false)
die('Could not write to text file.');
echo 'Text files have been merged.';
?>
I have the following code:
$markupimage = substr($product_info['image'],0,strrpos($product_info['image'],".")) . "-" . $popw . "x" . $poph . substr($product_info['image'],strrpos($product_info['image'],"."));
this currently outputs with $markupimage =:
http://shop.example.com/image/cache/data/NEW WEBSITE/Products/Hangers/Tees/Full Body/front_black-1000x1000.jpg
Where the 'NEW WEBSITE' text is, the php has missed out the url encoding. It should be NEW20%WEBSITE. How can I alter the php script to include this url encoding?
EDIT:
This is where I use this php script:
$this->document->setFBOG('og:image', HTTP_SERVER . 'image/cache/' . $markupimage);
I have tried wrapping this in both the rawurlencode() and urlencode()
So far I have tried:
$this->document->setFBOG('og:image', urlencode(HTTP_SERVER . 'image/cache/' . $markupimage));
$this->document->setFBOG('og:image', rawurlencode(HTTP_SERVER . 'image/cache/' . $markupimage));
This results in a link that looks something like:
http://shop.example.com/image/cache/data%2FNEW+WEBSITE%2FProducts%2FHangers%2FTees%2FFull+Body%2Ffront_black-1000x1000.jpg
You can use urlencode() function for that.
urlencode()
I'm very new to PHP, and as a challenge am trying to make a little inventory control script. The idea is to have the amount remaining of each item be defined through a PHP array, and then be imported into a javascript array for dynamic DOM insertion. The amount remaining of each item sits in a .ini file on the server.
This currently works with the below commented OUT code, but obviously I am defining the array values statically within the page:
<?php
//$quantity = fopen("quantity.ini", "w") or die("Its broked");
$quant = file("quantity.ini");
//$quant = array();
//$quant[0] = 13;
//$quant[1] = 90;
echo "var uniforms = [" ;
echo "{" ;
echo "\"item\" : \"Item1\", ";
echo "\"descr\" : \"Blue Hat\", ";
echo "\"size\" : \" 6-12 \", ";
echo "\"colour\" : \"Black/Blue/Green\", ";
echo "\"img\" : \" \", ";
echo "\"quant\" : \"" . $quant[0] . "\" ";
echo "}," ;
echo "{" ;
echo "\"item\" : \"Item2\", ";
echo "\"descr\" : \"Black Hat\", ";
echo "\"size\" : \" Large \", ";
echo "\"colour\" : \"Black\", ";
echo "\"img\" : \" \", ";
echo "\"quant\" : \"" . $quant[1] . "\" ";
echo "}," ;
echo "]" ;
for ($i=0; $i < count($quant); $i++)
{
fwrite($quantity, $quant[$i] . PHP_EOL);
}
fclose($quantity);
?>
I know that I don't need to echo the entire Javascript array, whoops :)
I had thought that each line of the file would be brought into a an array called $quant, as per this post.
The INI file, with the commented code invoked and the file() function removed properly writes to the .ini file as whatever values I modify quant[0] and quant[ 1] too.
Write out Jason using json_encode, JavaScript will read that fine, then you can get rid of most of your code
I realize the OP is new to PHP, etc...
But... the correct answer is: use a database, not a flat file.
it's relatively easy to set up a MySQL or SQLite db
Sorry