1

I created a few PHP files for users of a popular hardware site to use to "Metro" their news posts. It works fairly well, you add the title of the article, links etc. and then it spits it out in Metro tile format.

Take a look: http://briandempsey.org.uk/Newstool/index.php

When the user submits, it uses the information provided to create the post. Now, I need to somehow use PHP or some other language to display the code that it generated underneath it so users can just copy and paste it. I'm not sure how to do this.

2 Answers 2

6
header('Content-Type: text/plain');
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but I noticed another bug. If the user doesn't add 5 sources, it still shows the DIV's. Is there a quick way around this with javascript or something?
Shameless self bump, could I accomplish it with some Jscript?
Can't use javascript or HTML in text/plain mode - it simply outputs without any post-processing on the browser's end. You'll just have to filter the extra divs, or go with a completely different solution.
0

Since you're passing your form data using the method GET, you could instead pass it to a page that creates a url to pull the html from...

index.php will have the form as you've shown above and will post to urlCreator.php.

form.php can be deleted as it is not needed anymore, the magic will happen in the urlCreator.php file.

urlCreator.php (NEW) will have code in it like so:

<?php
    // urlCreator.php will get variables passed to it from index.php

    // Now create the url using the passed variables
    $url = "http://briandempsey.org.uk/Newstool/form.php?title=" . $_GET['title'] . "&color=" . $_GET['color'] . "&Articlecontent=" . $_GET['Articlecontent'] //and so on to build the whole url

    //Now get the pages html
    $html = file_get_contents($url);
?>

Now that you have the html in a variable you can clean it using str_replace or manipulate it however you'd like.

<?php
    // Still in urlCreator.php

    // With the html in a variable you could now edit out the divs and echo the results
    $html = str_replace("<div style=\"background-color: #008299; height: auto; width: 100%; margin-left: 10px;\">", "", $html); //removes the intro div
    $html = str_replace("</div>", "", $html); //removes the closing div

    //Finally echo out the html to the page for copy+paste purposes
    echo $html;
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.