I need to take all the files in the folder where the PHP file is, dump them together, and echo them. What is the simplest way to do it?
For example, I have the following files:
ILikeFish.txt
I like fish please bring me fish!
Well that's enough don't bring me anymore.
ILikePotatos.js
var Potatos = {yummy:true, amount:5323.6}
function potatoFunc(stuff) {
while (stuff=="cool") moreStuff();
}
Dawgz.png
Picture of a dog
Well, I want the output to be:
(.txt ignored)
var Potatos = {yummy:true, amount:5323.6}
function potatoFunc(stuff) {
while (stuff=="cool") moreStuff();
}
(Picture ignored)
How can I do it? Thanks for answering!
Also, I'm VERY basic in PHP and I know nothing, so please forgive me if this question is super dumb. Also, I AM aware of this question, but it doesn't answer how to do it!
Also, my final goal is to include all my libraries and comments using one line of
<script src="http://MySite/AllJsses.php"></script>
And again, Thanks for taking the time and answering!!!
Okay, after playing a little with google, w3schools and my genius brain I came up with the following:
<?php
$files = glob("*.js");
for ($i = 0; $i < count($files); $i++) {
echo file_get_contents($files[$i]);
}
?>
Thanks to myself and to some guy on other forums for answering this question! :D
Also, if any of you find any errors / performance issues / anything, please comment, because otherwise host gonna kill me. Thank you!
Related
***EDIT #3
Anyone who down votes this post has issues. Lets not act like we all haven't had a day in which we work so much, that something that should seem obvious, isn't. I genuinely looked for an answer, however, I worked so long that I could no longer think straight. Thanks again to those who helped, but down voting my post is juvenile and unnecessary. I hope I worded my question well enough so that someone searching for this like I was, has an easier time finding the answer before they look as silly as I did. Have a great day.
----------------------------Question Below----------------------------------
I am trying to write a script that will wrap a message with a tag in order to display the message in a specific styling in a command line application. My problem, is that I can't seem to output anything between <these brackets>. I know this is a PHP white belt issue, but my StackOverFlow and Google Fu is weak and pathetic right now and I can't seem to find the reason for my issue. Bellow is my code:
<?php namespace Acme;
class MessageWrapper
{
protected static $message;
protected static $tag;
public static function wrap($message, $tag)
{
self::$message = $message;
self::$tag = $tag;
// hides the $tag output, as well as the <>
// return "<$tag>" . $message . "<$tag>";
return $tag . $message . $tag;
}
}
$message = "Example message";
$tag = "error";
$example = MessageWrapper::wrap($message, $tag);
var_dump($example);
I am at a loss for what the issue is, and I am sure I'll feel like an idiot (if) when someone points out the issue, but I'm tapped out of ideas right now and I'd really like to understand better. Can anyone help a brother out?
EDIT**** In the command line application, it works as intended, however, I do not understand why no output to the browser. If anyone could provide me with some resources to point me in the right direction, much appreciation to you.
EDIT #2: I assume its because its trying to be parsed as HTML. Is there a way to format it in order to see it in the browser anyway?
The browser will parse it as HTML. If you want to see the raw HTML, use htmlspecialchars() to encode it:
echo htmlspecialchars($example);
Currently I'm having problems with rowClone and blockClone specially. In the documentation they says that if we use rowClone over a table with merged cells, the function (rowClone) will clone the adjacents rows, so I said, ok well, it looks pretty nice. So I made a table as you can see in the image 1, but when I execute the script, the function rowClone doesn't work as I was expecting.
Then reading the documentation deeper, I realized that there is another function called blockClone, but when I tried to use it, surprise, it doesn't work neither.
Finally I started looking for solutions on the Internet, but nothing they proposes help me, so please if you have any advice, hack, anything, please comment. Thanks in advance.
Image 1: template (.docx)
Image 2: result after processing the template
I found the bug in the source code. There is a space in a regular expression that made function preg_match does not match anything. Following I show you how to fix it:
This is the original code:
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
!preg_match('#<w:vMerge w:val="continue" />#', $tmpXmlRow)) {
break;
}
And this te code fixed.
if (!preg_match('#<w:vMerge/>#', $tmpXmlRow) &&
!preg_match('#<w:vMerge w:val="continue"/>#', $tmpXmlRow)) {
break;
}
The above if is between 298 and 302 in the source code (https://github.com/PHPOffice/PHPWord/blob/develop/src/PhpWord/TemplateProcessor.php)
I have hope it could help you!
I am looking at someones project and keep getting this line:
$resource_folder = getScenarioResourceFolder(getScenarioPath($scenario));
I cannot find any function that he implemented under those two names - getScenarioResourceFolder and getScenarioPath.
I started wandering that maybe the name Scenario has something to do with $scenario variable being in those functions. I know it might sound dumb, but I do not know what else to think.
Does anyone know about these function?
I know these:
You can search the function:
http://id1.php.net/manual-lookup.php?pattern=getScenarioPath if no
result, That is must be user-defined function.
You can check yourself by using
if (function_exists('getScenarioPath')) {
...
} else {
...
}
These are clearly custom functions that have been written in.
The simplest solution would be to GREP your entire system for getScenarioResourceFolder - you are looking for a .php file.
If you can't grep or don't know how, then it's time to go digging. Open any PHP files that are related to that project and look for getScenarioResourceFolder().
If you really don't have it, then you'll have to get in touch with the original architect of the project.
Does anyone know of any tutorials which take you though a step by step process on making a filesharing script I found lots of how to make file uploaders but none of them return a link for other people to download the stuff uploaded.
be great if someone could hit me back with some sort of tutorial for this
thank
Literally all you need is a hyperlink
<?php
//where
$url = "http://www.theurlineed.com";
$myuploadfolder = "/var/www/html/mydir/uploaddir";
if (is_dir($myuploadfolder)) foreach (scandir($myuploadfolder) as $file){
if ($file!="." || $file!=".."){
echo "<p>".$file."</p>\n";
}
}
?>
Almost certainly the issue is actually understanding for yourself the $url and the $myuploadfolder bit at the top. i.e. how to get from "serverland" to "url-land" and no-one can do that for you you have to suck it and see what works.
I know this must be a nooby question and I apologize but I can't find a straight forward answer anywhere!
Basically what I want to do is, if someone visits http://domain.co.uk/?debug then I want it to display additional information such as the code version or any other information I enter.
Again, I am sorry for the question but I really appreciate your help!
Thank you.
if (isset($_GET['debug'])) {
echo "Get the raid! There's bugs!";
}
As Hope4You pointed out, this is bad practice. But somehow this is very useful when deploying our application. One trick is to set up a "in development" flag.
<?php
define('DEVELOPMENT_SERVER', TRUE);
if (DEVELOPMENT_SERVER)
require 'debug_tools.php';
where debug_tools.php contains the code from MarcB and other helper functions.