Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP search & replace from index.php text boxes?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP search & replace from index.php text boxes?

Postby gowner » Mon Sep 17, 2012 11:29 am

Hi everyone, this is my first post here and I'm a PHP newb, so excuse me if this is easy mode. I know a lot of HTML, etc. a bit of a "copy paste coder", but this is my first time really trying to make a script.

Essentially what I want is a script where on the index.php there's 2 boxes, 1 for the base content, and another for the variable that needs to be replaced within the content.

The variable will remain constant, we'll call it %VARIABLE%. However the text replacing the variable will change each time.

This base content is fairly long so hopefully that wouldn't be a problem. I've found a lot of str_replace() scripts online but I don't want to have to change the file each time.

Any help, or pointing me in the right direction would be much appreciated.

Thanks!
gowner
New php-forum User
New php-forum User
 
Posts: 1
Joined: Mon Sep 17, 2012 11:25 am

Re: PHP search & replace from index.php text boxes?

Postby johnj » Mon Sep 17, 2012 11:05 pm

if you do not want to use str_replace then you should see if pattern matching regular expressions will help you. Here is an article that may help you -
http://phillipnb.wordpress.com/2011/03/ ... ns-part-1/
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP search & replace from index.php text boxes?

Postby kyle04 » Tue Sep 18, 2012 1:57 am

So you will have many pages in the format www.domain.com/index.php?pagename=x ?
With the variable text different for each pagename (x), or whatever the parameter name is.
If so you could use a database table to store the different text values for each pagename, then reference the relevent text from the current url :

Table fields :
PAGENAME
TEXT

<?
foreach($_REQUEST as $name=>$value) {
${$name} = $value;
}

$result = mysql_query("SELECT TEXT FROM TABLE_PAGES WHERE PAGENAME='$pagename'");
$row = mysql_fetch_array($result);
$thistext = $row['TEXT'];

?>

// text box display

<input type="text" value="<?echo $thistext;?>" >
kyle04
New php-forum User
New php-forum User
 
Posts: 94
Joined: Sat Jul 07, 2012 1:36 pm


Return to PHP coding => General

Who is online

Users browsing this forum: Baidu [Spider] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron