I am beginning to create a pattern library from BareBones. It uses PHP to pull in external HTML files to create the different sections. I would like to be able to have a heading and description for each section. BareBones seems to use a separate text file for the usage descriptions, which I could do for the heading too. This would mean I would have 3 files for each section though. Is there a better way to do this? Some thoughts I had, but haven't been able to figure out are:
Have heading as commented out first line of HTML file and then pull the first line via PHP
Create a variable in the HTML doc somehow and use it to store the heading and call it from the main file. I think to do this I would need to make all of the snippets PHP files though.
Any thoughts?
Related
I want to load all of my content pages off of one (or several depending on media type) php template. For simplicity sake lets just walk through one content type.
As of right now I have all of my content in text files, I plug it into individual divs. Each div is contained within a link that directs to its own php file. This seems extremely redundant and I'd like to cut out these extra php files.
The php template I use is simple and pulls in the text file that I manually plug in with this line of code. file() pulls out every line in target file and stores each line as an index in the array $myContent.
<?php
$myContent = file("contentTxt/006wakeWeRide.txt");
?>
Then I run down the data, and plug it into html accordingly.
The text files have some headers that I pull relevant data from followed by lines that contain the body of the writing.
1: txt //(type)
2: The Wake We Ride //(title)
3: SumOne //(Author)
4: 11/2017 //(date)
5: ./mats/philos.png //(thumbnail)
6: ./content/006wakeWeRide.php //(link to php file)
7..8..: Paragraphs go here //(content)
What I want, is to keep and maintain just the txt files, and to have them all refer to one template. After an hour of research I think I need to implement some sort of a GET request? And somehow pass the text file to load too it. Im not sure how to do this. Linking to the external php is easy. How do I link the user to the page while generating it?
I'm trying to design an interface to change <img> sources throughout my website, so that I don't need to change the sources by hand anytime we want to change what images my site displays.
I looked at DOMDocument already, and while it's useful for accessing the different elements in a file, it wraps the files in it's own HTML tags, which messes up the files (I already tried looking here but those solutions didn't work for me)
Is there a better way to take a file, retrieve element information and attributes (like src and id) from img tags, edit those elements, and save the file?
Just to close this up - I ended up using Querypath to accomplish this task. It works pretty well and was pretty simple to utilize.
I have a file that prints a variable from mysql database via php say it is called independent.php. if we open the file via localhost/independent.php the file displays the information with html.
Is it possible to include independent.php in another php file, and only display the contents generated via php and not the html of independent.php so that using ajax the new html appear?
If you want to use only specific parts of your code, make it modular. Break it down into functions and/or classes. Separate the HTML output from the part that fetches data so you can call both independently. There's no other sane way.
Is there some utility that could be called via command line to produce a doc(x) file? The source file would be HTML and CSS.
I am trying to generate Word documents on the fly with PHP. I am only aware of phpdocx library, which is very low level and not much use for me (I already have one poor implementation of Word document generation).
What I need from a document:
TOC
Images
Footers/Headers (they could be manually made on each HTML page)
Table
Lists
Page break (able to decide what goes to which page, eg one HTML file per page, join multiple HTML files to produce the entire document.)
Paragraphs
Basic bold/etc styles
I didn't find PHPDOCX very useful either. An alternative could be PHPWord, i think it covers what you need. According the website it can do these things:
Insert and format document sections
Insert and format Text elements
Insert Text breaks
Insert Page breaks
Insert and format Images and binary OLE-Objects
Insert and format watermarks (new)
Insert Header / Footer
Insert and format Tables
Insert native Titles and Table-of-contents
Insert and format List elements
Insert and format hyperlinks
Very simple template system (new)
In your case that isn't enough, but there is a plugin available to convert (basic) HTML to Docx and it works very good in my opinion. http://htmltodocx.codeplex.com/
I am using this for a year or two now and am happy with it. Altough i have to add that the HTML can't be to complex.
The way I usually do these is to have a word document template file with the parts I want to replace using keywords (usually something like "{FIRSTNAME}").
This allows you to read the file via PHP then simply do str_replace on all the parts you want to replace, then write that to another file.
Dynamic tables using this method are a bit more tricky, as you need a sub template for a row, which you can then include inside the main template as many times as required.
I'm not sure if this is the best solution, it's always seemed very fiddly to me and every time I'm asked to do this I get frustrated with it, but I guess it works. So if anyone knows a better solution I'd love to hear it too!
my head was spinning over this idea for a long time . and i though this is the right plce to ask for help ..
so what i want to do is make a really simple php file that make a search and replace in css files but the problem that i have is that a single css file can (as you all know ) have a 100 or more background tags and all i want to edit is one of them .. and what is some body added a line before or after ... so search and replace for the whole section of the css file that i want to replace well be useless unless it is all the same ..
i really have a bad time explanning but i hope that you get the main idea ..
all i want is some guidelines in this .. help is really appreciated/
I wouldn't suggest directly editing a linked CSS file through PHP (file_get_contents()) or something, but rather conditionally link different CSS files. Or perhaps, conditionally change what you need to change through CSS directly in HTML with PHP. For example, need to change background (for some reason) for different users, you would conditionally change the image source through PHP.
Why exactly do you want to do this? Maybe a CSS alternative like LESS is a viable option (it has support for variables etc)
You can either use php to load a stylesheet.php that is dynamically generated or use javascript to "compile" it on the client side (like LessCss)