PC Playground  

Go Back   PC Playground > The Core > Scripting/Programming
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-07-2003, 10:45 PM
Senior Member
 
Join Date: Jan 2003
Location: USA
Posts: 900
Send a message via AIM to headnerd
Default PHP Help?

How can I make a php script that like, wherever I put like... %T in the page, it would replace it with whatever the file name is.

So for example if the page was:

http://www.site.com/blah/is-a-sexy-guy.html

and in that page it said "Shaun %T!"

Then anyone who when to it, it would say "Shaun is a sexy guy!"
Reply With Quote
  #2 (permalink)  
Old 12-08-2003, 05:44 AM
Senior Member
 
Join Date: Jan 2003
Location: USA
Posts: 900
Send a message via AIM to headnerd
Default

nvm i figured it out
Reply With Quote
  #3 (permalink)  
Old 12-09-2003, 03:12 AM
Senior Member
 
Join Date: Feb 2003
Location: USA
Posts: 2,018
Send a message via AIM to zoid Send a message via MSN to zoid Send a message via Yahoo to zoid
Default

would you mind telling us not very php experienced webbies how you did that? i would like to learn this kind of stuff. (oh boy does it have many applications!)

oh gee the plastic min-baloons fell out of the pencils cup. :o
Reply With Quote
  #4 (permalink)  
Old 12-09-2003, 04:09 AM
Senior Member
 
Join Date: Jan 2003
Location: The Chair In Front Of My PC...
Posts: 597
Default

Basic String Replace....

read it here: http://http://us4.php.ne...eplace.php
Reply With Quote
  #5 (permalink)  
Old 12-09-2003, 11:51 PM
Senior Member
 
Join Date: Feb 2003
Location: USA
Posts: 2,018
Send a message via AIM to zoid Send a message via MSN to zoid Send a message via Yahoo to zoid
Default

would you mind posting the code? or a shortened version of the code for you doing that with the sitecom/blah thing?
Reply With Quote
  #6 (permalink)  
Old 12-10-2003, 12:31 AM
Senior Member
 
Join Date: Jan 2003
Location: The Chair In Front Of My PC...
Posts: 597
Default

This first example is simple...
In the str_replace() function, you have 3 terms. the first, %body%, is the term or terms that you want replaced. The second, black, is what you want to replace the first term with. The third is the code where you want the string replacement to occur...

Code:
<?php // Provides: <body text='black'> $bodytag = str_replace("%body%", "black", "<body text='%body%'>"); ?>
Next, using the array() function, we can choose multiple terms to be replaced. Therefore, with $vowels as the first term, you will replacing everything in the array (all the vowels). Leaving the second term blank (still quotations, but no space between) will cause no replacement in the third term, Hello World of PHP. Vowels will be removed and it will now be: Hll Wrld f PHP. Note, just in case, that everything in the array is being replaced by the same thing.

Code:
<?php // Provides: Hll Wrld f PHP $vowels = array("a", "e", "i", "o", "u", "A", "E", "I", "O", "U"); $onlyconsonants = str_replace($vowels, "", "Hello World of PHP"); ?>
Like the example above, we are replacing multiple terms in an array. This time, however, we have a second array which contains the three different words we want to replace the old words. All arrays are respective, so fruits is replaced with pizza, vegitables with beer, and fiber with ice cream. $newphrase then creates the new sentence with the str_replace function. Note that when using a variable in the str_replace function, no quotation marks are used.

Code:
<?php // Provides: You should eat pizza, beer, and ice cream every day $phrase = "You should eat fruits, vegetables, and fiber every day."; $healthy = array("fruits", "vegetables", "fiber"); $yummy = array("pizza", "beer", "ice cream"); $newphrase = str_replace($healthy, $yummy, $phrase); ?>
I hope that helps.


Code taken from [url=http://us4.php.net/manual/en/function.str-replace.php:alkwxme6]php.net[/url:alkwxme6].
Descriptions and explanations by me.



Headnerd, you can grab this if you want for your site.
Reply With Quote
  #7 (permalink)  
Old 12-10-2003, 05:44 AM
Senior Member
 
Join Date: Feb 2003
Location: USA
Posts: 2,018
Send a message via AIM to zoid Send a message via MSN to zoid Send a message via Yahoo to zoid
Default

niiice! the explanations help, it all seems so simple now...

thanks a, umm, potato!
Reply With Quote
  #8 (permalink)  
Old 12-10-2003, 09:19 PM
Senior Member
 
Join Date: Jan 2003
Location: USA
Posts: 900
Send a message via AIM to headnerd
Default

hmm...my code is MUCH more simple than all that O.o.

Anyways, im building a massive spider trap =)

lol.
Reply With Quote
  #9 (permalink)  
Old 12-10-2003, 10:29 PM
Senior Member
 
Join Date: Feb 2003
Location: USA
Posts: 2,018
Send a message via AIM to zoid Send a message via MSN to zoid Send a message via Yahoo to zoid
Default

sweet, i just dont know how i could apply it to how he explained that you just go to any .html file with that name in it, and it would do such a thing... headnerd you wanna step in
Reply With Quote
  #10 (permalink)  
Old 12-12-2003, 01:48 AM
Senior Member
 
Join Date: Jan 2003
Location: USA
Posts: 900
Send a message via AIM to headnerd
Default

nah it would need to be a php file
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:26 PM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.