Using php to insert data into a css file [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Hello, I Was wondering if there was a way to use php to call on a css file and insert data into it. The purpose would be to to allow a user to easily modify a css file instead of having to go into the file manually. It would be a field called Width: with a text area for them to enter it in.

Sure. You can easily read a file with file_get_contents and then write it back to the file with file_put_contents.
// load the css file into a string
$css = file_get_contents("my.css");
// make changes, e.g....
$css = str_replace("width: 10px;", "width: 20px;", css);
// save those changes
file_put_contents("my.css", $css);

Create an script to "generate special css" using functions like fwrite() that will create an special css for each user and then load it if user is logged to overwrite the original css

Related

How to find a file and include another file into it? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I'm using a plugin that updates alsmost evert week, and when that happens it overrides every work that I've done. I welcome the updates but not when it overrides my inputs. I'm trying to keep my inputs in seperate file and have a code in place that will find the pluging file and include my inputs as a file. That way nothing will break, my inputs and the updates will both be intact. my code looks like below.
$useThis = 'search-processor.php';
$putHere = "um-actions-members.php";
file_put_contents($useThis, $putHere, FILE_APPEND | LOCK_EX);
This way you will not parse the PHP commands, you only include what is inside the php file
$useThis = "search-processor.php";
$putHere = "um-actions-members.php";
// get the content of $putHere
$fileContent = file_get_contents($putHere);
file_put_contents($useThis, $fileContent, FILE_APPEND);
To parse the PHP commands you need to go inside the $useThis and use the include command, like
include("um-actions-members.php");

How to generate new page on my website using PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can i create new page on my website using PHP? I need PHP-code, which can create a new page. For example, i've got index.php and i need to create index2.php w/ PHP. Thanks.
Like above answer you can use fopen() and fwrite() to build a new .php file, or you could try using file_put_contents() which would also generate a new file if it doesn't exist.
file_put_contents($filename, $content);
Example
$filename = "index2.php";
$content = "<h1>hello world</h1>";
file_put_contents($filename, $content);
Use fopen() to create a file, and fwrite to edit it, more info here :
http://www.w3schools.com/php/php_file_create.asp
Open Notepad (if your do not have any other softwares like Notepad++ or Dreamweaver for editing PHP code), write your code there, Save the text file with .php extension in the same directory where your index.php file is located.

How to get codes from another page? (Basic PHP) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want something like Wordpress's system. I want to get header code from header.php so I will not have to edit all of the pages when I'm going to edit something.
You can never get the code because one the php page is render, it gets converted into HTML so you will always see html.
I understand, you need header component.
1)Create a file header.php (add navigation bar or logo or whatever you want).
2)Include it in other php files as include("header.php");
so all the pages will be using this one header.php file and you can modify it and the changes would get reflected all over the web app.

retrieve a web page without images [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am writing a web scraper for a specific site using PHP.
I use file_get_contents function to retrieve web pages.
some pages have images and images are also retrieved with the page.
In my case I don't want images to be there. (I want text only)
my question is, is it possible to retrieve pages without images? if so how?
additional info: I have checked the source of the page. there base tag is defined inside head tag and pointing to the same url.
Edit: I just notice images are base64 encoded.
It is not possible to "retrieve" the page with the images not included. You would need to parse/scrub the contents after retrieving it.
Inline with a previous comment, one method (of several) is this way if you simply need the image tags removed:
$data=file_get_contents();
preg_replace("/<img[^>]+>/i", "(image) ", $content);
echo $content;

How to extract complete html source code and save it in a text file by using php [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to extract the source code from a website and want to save it in a text file on wamp server. So kindly help me.
It is not very complicated, you can get the content of a file by calling file_get_contents() this includes files on the web.
Then you just need to write the content to a file and presto you have extracted the .html source and saved it in a text file by using php.
<?php
// Open a webpage
$homepage = file_get_contents('http://www.example.com/');
// echo the homepage to see the content.
echo $homepage;
// Set the filename
$file = 'hp.txt';
// Write the contents back to the file
file_put_contents($file, $homepage);
?>
Hope this is what you need.

Categories