Forum Moderators: coopster

Message Too Old, No Replies

How To Dynamically Generate Webpages

Replacing #*$!xx with given data

         

nguyen

12:27 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



Greetings!

First off I want to say hi. I think this is my 1st post here. I'm very much new and not much of a technie but I'm learning all I can.

Wow, you guys know so much about so maybe you can shed some light on this. I don't really know if this is the place to ask but here goes.

Let's say I have a web template and I want to my visitors to be able to replace certain data with their own.

For example, anywhere I have '#*$!xx' (five x's without the single quote, it's not coming out right after the post) would then be replaced with whatever they entered in a form. So someone would visit my page and upon entering 'abcd' in the form and hitting the submit button would then pops up the template page for him/her with all the '#*$!xx' replaced by 'abcd'.

Another way would be something like this...

www.mysite.com/?xxxxx

The visitor simply replace the 'xxxxx' in the link above with 'abcd', reload the browser and all the places with 'xxxxx' in the html would be replaced with 'abcd'

I'm guessing this would be really simple to do. It's probably using php right? Could someone shed some light on this please.

Thanks

Nguyen

coopster

12:34 pm on Nov 17, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, nguyen.

PHP has a str_replace() [php.net] function that may interest you.

Stu_Rogers

3:51 pm on Nov 17, 2005 (gmt 0)

10+ Year Member



Nguyen,

You are quite right in saying there are two ways to achieve this: Posting a form value back to the page, or tagging a parameter on the URL.

Here are both methods, in very simple PHP scripts:

1. Using a form

<?
echo ("
<form method='post' action=" . $_SERVER['PHP_SELF'] . ">
<input type='text' name='myname'>
<input type='submit' value='submit'>
</form>
<p>My name is " . $_POST['myname'] . "</p>");
?>

Simply save as a php file, upload and test.

2. Using a parameter

<?
echo("
<p>My name is " . $_REQUEST['myname'] . "</p>");
?>

Save as a php file, for example page.php, then upload to your server, open in a web-browser and add this parameter to the end of your URL…

?myname=Nguyen

(so your full URL looks something like [mysite.co.uk...]

Is this what you need to get you started?

nguyen

11:09 pm on Nov 18, 2005 (gmt 0)

10+ Year Member



Stu_Rogers,

Wow, you guys always seem to amaze me. You sure seem to know what you're talking about. I, on the other hand, haven't the slightest clue. So if it seems elementary please forgive me. I don't know anything about programming but I try to use as much gray matter (common sense) as possible...hihi.

I think you almost hit it on the head here...

Both methods will will output a line of text on the screen right?

But what if I want to call up a webpage instead?

Ok, let's back up a second...

Forget using a form for now because I don't think it will work the way I want it to.

2. Using a Parameter

<?
echo("
<p>My name is " . $_REQUEST['myname'] . "</p>");
?>

Given the example above, if I type:

[mysite.co.uk...]

in my browser, I will get:

My name is Nguyen

on the screen right? And replacing 'myname=Nguyen' with 'myname=anything' will show "My name is anything". Is that right?

But what if I want to load a webpage template instead?

Do I put the template's HTML code somewhere in the php code while replacing instances of my name, Nguyen, in the template with a token of some sort?

To be more specific let me give a situation where this would apply...

Let's say my site is [mysite.com...] and I host pages for members based on a template at [members.mysite.com...] (this will function the same as [mysite.com...] right?).

So the template file would actually be index.htm or index.html

Now say thoughout the template I have links I want the members to be able to brand with their own. for examples here are some of the links in the template:

[#*$!.mysite.com...]
[xxx.yoursite.com...]
[somesite.xxx.com...]
[hersite.com...]
[oursite.com...]

The links above are in the HTML code itself and not necessary what's on the screen. (example: <a href="http://xxx.mysite.com">Click here</a> )

To direct visitors to their own page with their branded links they would direct visitors to:

[members.mysite.com...]

replacing xxx with their info. So if they direct visitors to:

[members.mysite.com...]

the example links above on the page would now take visitors to:

[nguyen.mysite.com...]
[nguyen.yoursite.com...]
[somesite.nguyen.com...]
[hersite.com...]
[oursite.com...]

Hmmm...when making the template I would probably need to replace all the xxx with some sort of token?

And in the php code (or not php?) somewhere, it would load the template replacing tokens with the parameter, depending on what the URL was?

Sorry guys if I tend to be long winded. I just want to be clear so to give you a better understanding of what I'm thinking.

Thanks!

Nguyen