7 Replies - 1530 Views - Last Post: 26 November 2009 - 10:42 AM Rate Topic: -----

#1 hockey97   User is offline

  • D.I.C Regular

Reputation: -77
  • View blog
  • Posts: 300
  • Joined: 25-September 08

php manipulating the html code and css code.

Post icon  Posted 21 November 2009 - 02:35 PM

Hi, I want to create a gui interface for users to edit how the site layout looks. Then save it.


Well, I know how to do do with javascript to create the gui and store the values to a file.

The problem I face is editing the file. I want to user to be able to later on add stuff or delete stuff from the layout.

Now comes to question how can I use php to look at the html and css files and edit just a single code in that file.

for example if the user adds 5 youtube videos. Then lets say a week went by and decides to delete youtube 3. How can I just use php and go and search for youtube 3.


Do you think I could use AJAX or jquery to grab the id of each html element?

what about css?

I want to directly delete or overwrite the code that is needed.

I was thinking to make a id generator. So the id is like youtube#1

and keeps counting. I am guess I can search and find the id that matches the id of the element the user either deleted or moved around or to another post on the layout.

I would like to know how you or others work with html and css code with php. Meaning how do you find specific code that needs to be modified.

Is This A Good Question/Topic? 0
  • +

Replies To: php manipulating the html code and css code.

#2 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: php manipulating the html code and css code.

Posted 21 November 2009 - 09:46 PM

In this case what I am going to do is read file with PHP and then print the file in textarea after saving I am replacing the text in html file,
But it would be better to use a database example: if I want to show videos from youtube then I am saving its path in database and then getting all result from table and then printing the values or path in the page,
and after a while I want to remove a file then I easily can delete the file path from table and it is not showing in the page.
$str = "SELECT * FROM table_youtube";
$query = mysql_query($str)or die(mysql_error());
if(mysql_num_rows($query)>0){
	while($fetch = mysql_fetch_assoc($query)){
		echo $fetch['file_path']; // file path from youtube webiste which is stored in my table
	}
}


Hope it helps :)
Was This Post Helpful? 1

#3 rhodry_korb   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 14-November 09

Re: php manipulating the html code and css code.

Posted 21 November 2009 - 11:18 PM

I am interested in this conxept too
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6876
  • View blog
  • Posts: 31,671
  • Joined: 10-May 07

Re: php manipulating the html code and css code.

Posted 22 November 2009 - 12:16 PM

When I did this in the past, I set session values to the *as suggested above* loaded sql values that were preset by the user. Then each PHP page would load the session values into a local value, thus all of the code stayed the same.

Maybe this is useful, maybe not. But that's how I did it.
Was This Post Helpful? 0
  • +
  • -

#5 rhodry_korb   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 14-November 09

Re: php manipulating the html code and css code.

Posted 25 November 2009 - 07:15 PM

So you want to using PHP e able to read a CSS and then save any changes to it? After editing it using GUI.
Was This Post Helpful? 0
  • +
  • -

#6 BMR777   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 41
  • Joined: 01-February 09

Re: php manipulating the html code and css code.

Posted 25 November 2009 - 07:20 PM

I have a site where users can create their own websites via a custom PHP based CMS and they also are able to edit the CSS. What I do is I store their CSS stylesheet in the database so they can edit it using the CMS PHP script. Then in the .html file that uses the CSS stylesheet I have the CSS stylesheet location set to css.php?id=1. The css.php file will read from the database whatever the given css id is and then output the CSS with a content type of text/css. The browser is then tricked into thinking the CSS is from a css file, even though it is from the database. :)

This post has been edited by BMR777: 25 November 2009 - 07:22 PM

Was This Post Helpful? 0
  • +
  • -

#7 rhodry_korb   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 67
  • Joined: 14-November 09

Re: php manipulating the html code and css code.

Posted 25 November 2009 - 07:50 PM

BMR777 I am sure it would be helpful if you could please provide the source code, and how exactly does it get stored in the database (a table structure) would be appreciated
Was This Post Helpful? 0
  • +
  • -

#8 BMR777   User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 41
  • Joined: 01-February 09

Re: php manipulating the html code and css code.

Posted 26 November 2009 - 10:42 AM

View Postrhodry_korb, on 25 Nov, 2009 - 06:50 PM, said:

BMR777 I am sure it would be helpful if you could please provide the source code, and how exactly does it get stored in the database (a table structure) would be appreciated


Sure. :)

This is the CSS Loader file, which outputs the CSS to the browser.

<?php

// Link this file to the rest of your script up here...
// Establish your database connection before proceeding...

// GRAB THE CSS FILE TO BE LOADED...

$id = $_GET["id"];
$id = preg_replace("/[^a-zA-Z0-9\\040.]/", "", $id);
$id = mysql_real_escape_string($id); 

// Load the CSS file...

$query = "SELECT * FROM yourtableprefix_css WHERE id='".$id."'";
$result = mysql_query($query);
$num = mysql_numrows($result);

if($num > 0){

// There is a CSS file that exists

$i=0;
while ($i < 1) {

$[email protected]_result($result,$i,"content"); 
$css = stripslashes($css);

$i++;
}

header("Content-type: text/css");
echo $css;

}
else{

echo "The CSS File Could Not Be Located!";
die("");

}

?>


And the table structure...

CREATE TABLE yourtableprefix_css (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, themename varchar(50), content varchar(15000));


Then just store your CSS in the database table. Simply make a HTML form where the user can insert / edit the CSS and then POST that to a PHP script to insert that into the database. :)

This post has been edited by BMR777: 26 November 2009 - 10:45 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1