trying to extract data from txt file into and html - html

guys I'm doing a project game, and I'm having a struggle when I try to extract a text file content into an HTML I made.
currently, the game creates a score.txt file with the player score, and I'm trying to make an HTML that will show this score in the HTML automatically.
I will add my current HTML for reference so you could check it out:
This is the part of the code I'm struggling with
<h1><div id ="score">The score is <?p$ filename =
fopen('score.txt', 'r');
$file = fread($filename, filesize('score.txt'));
echo $file;
fclose($filename); </div> </h1>
<hr class="w3-border-grey" style="margin:auto;width:40%">
<p class="w3-large w3-center">Good job traveler!</p>
</div>
<div class="w3-display-bottomleft w3-padding-large">

<?php $myfile = fopen("webdictionary.txt", "r") or die("Unable to open file!"); echo fread($myfile,filesize("webdictionary.txt")); fclose($myfile); ?>
This should solve it
If in any case it doesn't work please refer to this url https://www.w3schools.com/php/php_file_open.asp

Related

How to make my RSS Feed use more than one image for each news?

Sorry for my really bad english (I also dont know how to build the title very well but I hope it's good enough to understand what I'm trying to do).
I bought this website template, the guy I bought it from has corona and is unavailable right now, that's why I'm asking for help here ^^
This is my homepage https://www.ragnarokeurope.net/
When you open this page, you see my News RSS feed and 4 pictures.
What I'm trying to do is: use a different picture for each of the news.
If you don't want to click the link, here is a picture of what Im talking about
The code for the pictures, I have it here. As you can see, it's made so everything uses the same picture. It would be awesome if somebody could help me change it.
<div id="RO_ACTU_IMG">
<?php
$newslimit = (int)Flux::config('CMSNewsLimit');
require_once('autoloader.php');
$feed = new SimplePie();
$feed->set_feed_url(Flux::config('CMSNewsRSS'));
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();
?>
<?php foreach($feed->get_items(0,4) as $rssItem): ?>
<?php
// These News Images are stored in /themes/<theme_name>/img/news/
// In the if-statement, use the name of your News item to dsiplay $newsimage in the feed.
if($rssItem->get_title() == "The League Of Levelers"){$newsimage = "league";}
elseif($rssItem->get_title() == "Halloween Has Landed"){$newsimage = "halloween";}
else{$newsimage = "generic";}
?>
<div class="RO_ACTU_IMG_news">
<img src="<?php echo $this->themePath('img/news/'.$newsimage.'.jpg') ?>" alt="NEWS">
<div class="RO_NEWS">
<h3 class="RO_NEWS_titre"><?php echo $rssItem->get_title() ?></h3>
<p><?php echo date(Flux::config('DateFormat'),strtotime($rssItem->get_date()))?></p>
<p><?php echo substr($rssItem->get_description(),0,170) ?>...</p>
<div class="RO_readmore"><p>Read more</p></div>
</div>
</div>
<?php endforeach; ?>
It looks like that it is possible that get_Title() is not eval'ing to your text. None of the titles in the image match the text you are comparing as well.

Magento: remove <p> tags from the header logo image - "Need file path"

What I'm attempting to do is to remove some <p> tags that wrap the header logo image which does not contain any text because I think they should not be there.
But this is throwing the following error when testing via the W3-validator.
Line 261, Column 216: Element p not allowed as child of element a in
this context. (Suppressing further errors from this subtree.)
What file should I look in to locate line 261?
I'm stuck. I've searched for hours and can't find the file-path to the file that contains the string I need to edit. I currently don't have access to link hints function so that out of the question.
Any suggestions would be highly appreciated.
Thanks a million
Fish
Update: Here is some code regarding the logo from the header.phtml
<div class="header-wrapper <?php echo $hdr_style?>">
<header>
<?php if ( $config['design']['below_logo'] ) : ?>
<div class="row clearfix">
<div class="grid_12">
<?php if ($this->getIsHomePage()):?>
<h1 class="logo"><strong><?php echo $this->getLogoAlt() ?></strong><?php echo $this->getChildHtml('theme_logo', false) ?></h1>
<?php else:?>
<strong><?php echo $this->getLogoAlt() ?></strong><?php echo $this->getChildHtml('theme_logo', false) ?>
<?php endif?>
The code comes from <?php echo $this->getChildHtml('theme_logo', false) ?>.
You need to check the layout files in the theme and see which template the 'theme_logo block' is using. That's where you can find and remove the <p> tags.

EntityMalformedException when retrieving Drupal 7 custom field

I am playing with Drupal and I am trying to add a second line to the site slogan.
The following is the piece of page.tpl.php where I am working.
<?php if ($site_name || $site_slogan): ?>
<div id="name-and-slogan" class="hgroup">
<?php if ($site_name): ?>
<h1 class="site-name">
<a href="<?php print $front_page; ?>" title="<?php print t('Home'); ?>">
<?php print $site_name; ?>
</a>
</h1>
<?php endif; ?>
<?php if ($site_slogan): ?>
<p class="site-slogan"><?php print $site_slogan; ?></p>
<?php endif; ?>
<?php
/* ADDED */
$node = menu_get_object();
$siteslogan2 = field_get_items('node', $node, 'field_siteslogan2');
?>
<?php if ($siteslogan2): ?>
<p class="site-slogan2"><?php print $siteslogan2; ?></p>
<?php endif; ?>
</div>
<?php endif; ?>
I basically added a new Content Type with a field called siteslogan2 (field_siteslogan2) and now I would like to retrieve and show it here.
The first problem is that the $node var is not defined (even if according to the documentation it should be). The second problem is that I receive EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids() when I define it manually and run it.
First of all, is this the right approach to the problem? Secondly, why do I receive the EntityMalformedException and how can I fix it?
var_dump($node) produces NULL. It must be the way I get the $node content that is not good. The doc is a bit cryptic to me when it says:
$node: The node object, if there is an automatically-loaded node associated with the page, and the node ID is the second argument in the page's path (e.g. node/12345 and node/12345/revisions, but not comment/reply/12345).
This sort of thing is can be done using a preprocessing function in your theme's template.php to define and set a variable in the $varables array.
This variable then becomes available to whichever template ( page, node, form, etc ) you have done the preprocessing on. Your theme's template.php file will most likely have comments on how to do this.
for instance, doing this in the template.php creates or modifies the value of the variable $display_header, making it available for use in node.tpl.php
function yourthemename_preprocess_node(&$variables, $hook) {
$variables['display_header'] = false;
}
You can then modify the node template file to use this variable.
For something simple like a sub-slogan, you can add a setting to the theme, so it shows up on the theme's configuration page like any other theme setting.
This requires implementing this function in your theme's theme-settings.php:
function yourthemename_form_system_theme_settings_alter(&$form, $form_state) {}
This provides information to the settings form regarding the new setting. like this:
https://api.drupal.org/api/drupal/modules!system!theme.api.php/function/hook_form_system_theme_settings_alter/7
Hopefully that's enough to get you started.

HTML code to upload images

Can someone please provide me with some links (or source code) for me to research about how to upload images to a website (by the community) and for these images to be viewed online by the community.
I have searched via google, but have had no luck.
Thank you.
EDIT
Sorry, I have actually seen many examples to upload files. I am wanting (if possible) to be able to upload images, and then have them arranged in some kind of gallery so that the community can see/view them.
I am after a range of different technologies that are available on the WWW if possible.
Copy the below codes and save it as upload.php or anything.php (note it should be saved as php extension and should be run on apache server or any server supporting php).
<?php
if(isset($_REQUEST['submit']))
{
$filename= $_FILES["imgfile"]["name"];
if ((($_FILES["imgfile"]["type"] == "image/gif")|| ($_FILES["imgfile"]["type"] == "image/jpeg") || ($_FILES["imgfile"]["type"] == "image/png") || ($_FILES["imgfile"]["type"] == "image/pjpeg")) && ($_FILES["imgfile"]["size"] < 200000))
{
if(file_exists($_FILES["imgfile"]["name"]))
{
echo "File name exists.";
}
else
{
move_uploaded_file($_FILES["imgfile"]["tmp_name"],"uploads/$filename");
echo "Upload Successful . <a href='uploads/$filename'>Click here</a> to view the uploaded image";
}
}
else
{
echo "invalid file.";
}
}
else
{
?>
<form method="post" enctype="multipart/form-data">
File name:<input type="file" name="imgfile"><br>
<input type="submit" name="submit" value="upload">
</form>
<?php
}
?>
And you should create two folders("uploads" and "tmp") in the parent directory (Where the script executes).
Now your upload script is ready. It's simply an upload script with which you can upload one image at a time.
Here's a good, basic start using PHP: http://www.w3schools.com/php/php_file_upload.asp
In order to get a list of files in a directory (assumes the file path is known ahead of time) you can do something like this:
$filePath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'uploads';
$files = scandir($filePath);
If you wanted to filter this down to look for image files you could use something like this:
$filePath = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'uploads';
$files = scandir($filePath);
$imageFiles = array_values(preg_grep('/^.*?\.((gif)|(png)|(jpe?g))$/', $files));
And for a good guide on uploading the files you can check out http://www.exchangecore.com/blog/how-upload-files-html-php/

How can I append a <span> tag to a <h1> heading in Wordpress

I need to add a spantag to an h1 heading in wordpress. I tried writing in through the CMS but it renders the spantag as text.
The site's title is a name and I want to give different styles to the words.
Suggestions?
Following David Thomas's advice I've written this: but it appends the span last and empty.
<h1>
<a href="<?php bloginfo('url'); ?>/">
<?php
$completeName = bloginfo('name');
$split = explode(" ",$completeName);
echo $split[0]."<span>".$split[1]."</span>"
?>
</a>
</h1>
You should be using get_bloginfo as Felipe suggested, but still pass in the 'name' parameter.
I was just working on the same code for the same reason and thought I should post for future visitors:
<?php
$completeName = get_bloginfo('name');
$nameParts = explode(" ", $completeName);
echo '<span>'.$nameParts[0].'</span> '.$nameParts[1];
?>
Apply the style to the h1 instead.
By the way, you probably want to edit the theme.
What about:
<? echo get_bloginfo('name', 'raw'); ?>
Can't test it for now, but here's the documentation about it:
bloginfo()
==> it just echoes the result of get_bloginfo() and there's a second parameter to this function
==> wptexturize(), a function that WON'T be called so beware!