I have a very simple php script, of which is made to read the content of a file and then print it out on the site, using the method "readfile();" Here below you can see my code.
<?php
$readThisFile = './myFile.txt';
readfile($readThisFile);
?>
Now my question is whether it is possible to change the color of the text outcome, of which is visible on the website page. To give an example, once the php method has run and read my file and it outputs "hello world" on the site, because that is whats inside. Then the output is in black like any regular text, I was wondering whether it is possible to change that outcome to white or alike so that it is "invisible" on a white page.
I have seen it is possible to do this if the content which is on the site is "echoed" and not "read" like below here.
<?php
echo '<span style="color:white; align:center;">Hello World!</span>';
?>
But if that is possible to do with "readfile();" as well, I am not completely sure how I would implement it.
You can always do this:
<?php
$readThisFile = './myFile.txt';
echo `<span style="color:white; align:center;">`
readfile($readThisFile);
echo '</span>';
?>
Put the read text inside other element :)
Related
I added a simple PHP echo tag on my website:
<?php echo "Test"; ?>
This message should be displayed above the header (which has a green background. The header moves a little, but I can't see the text "Test".
Then I tried this code:
<?php echo "<h1>Test</h1>"; ?>
Again, the header moves a little more, but the text is invisible.
First:
After the normal echo tag:
After adding h1:
Can you help me?
Your PHP echo needs to be inside the HTML body element to be displayed on the page. Everything else you see is a result of the browser attempting to correct invalid HTML (which can look very different between different browsers).
I am fairly new to the code world and am trying to display an image inside of an echo string.
Here is the code
<?php
echo String::insert(
__("Are you owner of this listing? :claim_link"),
array('claim_link'=>$html->link(
__("CLAIM IT NOW"),
array("controller"=>"listing_claims",
"action"=>"claim",$listingData['Listing']['id']
)
)
))
?></div>
The code works fine, however, I want to replace ... (__("CLAIM IT NOW") ... with an image instead of just text...something like 'img src='my-image.png'. The goal is to get a button to appear instead of text.
so far, when I make the change, I see whatever text I have typed in.
Any help is appreciated.
Replace:
"CLAIM IT NOW"
with:
"<img src='yourimage.png' alt='Image'>"
If you are using CakePHP you should do something like:
$html->link($html->image('yourimage.png', ...
First off, I'm brand new to PHP so I'm sorry if this is a stupid question, second of all sorry if this title is incorrect.
Now, what I'm trying to do is create an overlay for a game that I play. My code for the overlay works perfectly, and now I'm working on my HTML file which gets its information from a website and outputs it. The code on the website looks like this:
<span id="example1">Information I want</span>
<span id="example2">More Info I want</span>
...
<span id="example3">And some more</span>
Now what I want to do is create a PHP script which goes in and finds elements by their names and gives me the information in those span tags. Here's what I've tried so far, it's not working however (no surprise):
//Some HTML here
<?php
$doc = new DomDocument;
$doc->validateOnParse = true;
$doc->Load('www.website.com');
echo "Example1: " . $doc->getElementById('example1') . "\n";
?>
//More HTML
To be honest, I have no clue what I'm doing. If anyone could show me an example of how to do this properly, or to point me in the right direction I would appreciate it.
The text between open and close tags is a Text Node.
Just write $doc->getElementById('example1')->nodeValue
Your code seems along the right lines, but you're missing a few things.
First of all, your load call is literally looking for a file named "www.website.com". If it's a remote file, you must include the http:// prefix.
Then, you are attempting to echo out the node itself, whereas you want its value (ie. its contents).
Try $doc->getElementById("example1")->nodeValue instead.
That should do it. You may want to add libxml_use_internal_errors(true); so that any errors in the source file won't destroy your page with PHP errors. Also, I would suggest using loadHTMLFile instead of load, as this will be more lenient towards malformed documents.
you can use getElementById:
$a = $doc->getElementById("example1");
var_dump($a); so you will see what you want to echo or put, or something.
You can also make all the names i HTML as example[] end then foreach the example array, so you can get element by id from example array with just one row of code
I'm having a little problem here and I would much appreciate your help.
I'm trying to create a sort of menu which will be displayed after a user logs in in Joomla (the fact that is joomla doesn't really matter though). I have two different outputs for two different users. If the user is User A, s/he will see output A, if it's user B, s/he will see output B.
I have already figured out how to do the "Look who's the user---give output" part. And it's working perfectly. The problem is the output itself. I'm trying to echo a div which contains an image and a text, both as a link. However, the only output I'm getting is the text, whith no format whatsoever.
Here it's the code:
<?php
$user =& JFactory::getUser();
if ($user->id == 291) {
echo <<<EOS
<div class="mitribu"><img class="mitribuimg" src="images/banners/books.png" alt="books"/>Mi tribu</div>
EOS;
}
?>
As you see this should render an image and the text Mi tribu, and that should be a link. But the only thing I'm getting is Mi tribu in plain text.
What Am I doing wrong here?
Thank you very much in advance!
Hernan.
EDIT: I have found the answer. It was the plugin used to render PHP inside articles and modules in Joomla, Sourcerer, which was stripping the code. Just in case someone else has the same problem, here it's the solution:
You must use {source 0} {/source} to add the code. Adding the 0 tells the plugin to do not strip the HTML code.
Have you tried opening it in Google Chrome? Then rightclick where the image should be (so on the text) and choose "inspect element" from the menu.
This will bring up the debugging tools from Google Chrome, and will allow you to see what's been output to the browser, and might show you why your image is not visible (wrong path or something alike).
You can execute HTML inside of php code easily like this below. Instead of using { } just use the colon and output the html below.
$user =& JFactory::getUser();
if ($user->id == 291):
?>
<div class="mitribu"><img class="mitribuimg" src="images/banners/books.png" alt="books"/>Mi tribu</div>
<?php endif;?>
or do this, make sure to use the ' because you are using " in your HTML.
<?php
$user =& JFactory::getUser();
if ($user->id == 291) {
echo '<div class="mitribu"><img class="mitribuimg" src="images/banners/books.png" alt="books"/>Mi tribu</div>'
}
?>
Im using a php include and i want to limit how much is shown at the first page:
1.php
<?php include('dynpage/some_text.htm'); ?>
2.htm
<p style="margin-left: 80px;"> <strong>some title nr.1</strong></p>
<p>Some text nr.1</p>
<strong>some title nr.2</strong>
<p><strong>NB!</strong>some really long text</p>
i want that "1.php" is showing only "some title nr.1" and "Some text nr.1"
i tried different codes i found from internet but none of them worked.
Thank you
I believe you will have to make the logic to display limited data on 2.htm (I suggest make it a php file).
Pass a parameter to the second php file and based on it display the data.
Something like include file like "2.php?showless=true"
On 2.php write.
$showless = $_GET['showless']
if($showless =='true'){
echo // what you want to show
}{
echo // for other cases show everything.
}