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>'
}
?>
Related
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 :)
I have a administration corner on my web, where can Admin create and post news.
It's implemented with html alements as helper. Admin clics on buttons and elements helps him, to style his text.
It looks this:
I have an option to Edit existing News as well.
Problem is if I try to assign this html text into my variable in ng-init
It all go bad.
<h4 ng-init="TextAreaText = '<?php if ($_GET["NID"]) $Admin->DrawNewsByID($_GET["NID"]) ?>'"> Editor </h4>
It means if there is NewsID in Get, It selects News text in php and tries to assign it into TextAreaText varible.
But it is shown like this:
Because of my bad quotation marks.
As you can see: - source code from my browser
Is it possible to samehow fix it?
Thanks a lot.
The table cell in the below code is being used as part of a messaging system and it returns the url as a link to the attached file to the message.
echo '<td width="25%">'.wp_get_attachment_url($row->file_attached).'</td>';
This is fine and works well, my problem is that I would like it to either only show the title of the file ( not the full url)
or even better would be to have it print "file attached" as a link, but if there is no file to get could it say "no file attached"
I am a complete novice at this and I am trying to stuble my way through. It would be great if somebody could push me in the right direction.
Thanks
If you just mean you want the text of the link to be different, this is really basic HTML (not PHP):
some text for the link
In your case, you have the URL repeated as the contents of the <a> tag, but you can put whatever you want there.
Edit: To only show the link if there is a link to show, you need an if statement, probably the simplest piece of programming logic there is:
if ( $row->file_attached ) {
// echo a link
}
else {
// echo something other than a link
}
Try following. when attachement is found it displays your link, when its not found it just shows a message. It is not a good idea to have a link when no attachement is found, that will link to nowhere...
if(wp_get_attachment_url($row->file_attached))
echo '<td width="25%">'.sometext.'</td>';
else
echo '<td width="25%">no file attached</td>';
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 trying to retrieve the game mode of a server.
This is the code:
<p>
<strong>Grand Bazaar</strong>
<span class="bullet">•</span>
Rush •
<img src="src.png">
</p>
I'm trying to find Rush. I tried this script:
foreach($html->find('p .bullet') as $e)
{
$mode = $e->nextSibling ();
}
But the script just skips "Rush" and continues over to the next tag.
I'm sure you guys know what you're doing better than me.
Could anyone help me out here?
You need to make your questions clearer mate... "I'm trying to retrieve the game mode of a server" <- This is irrelevant in relation with your problem for example.
The problem you're having is that "Rush" is nothing but text, it's not a sibling of .bullet as that would imply Rush being the content of a tag that's a sibling to .bullet, say
<span class="bullet">•</span>
<span>Rush •</span>
<img src="src.png">
If the structure you presented is identical all the time though, and you're using Simple HTML DOM by the looks of the code (http://simplehtmldom.sourceforge.net/), then you could maybe clear the contents of the tag first:
$strong = $html->find('strong'); // I think you can use prevSibling in your example
$strong->innerText = null;
And then just strip_tags() on the whole paragraph and get the text?