Click to See Complete Forum and Search --> : Using ereg_replace


troy1984
11-21-2003, 02:29 AM
I want to know how to use "ereg_replace" in a template class.
These are my files:


Controll Class __________________________________
<?php
include("include/dbclass.php"); // bestanden includeren tot de klasse
include("include/tpclass.php");

class pagina // klasse pagina aanmaken
{
var $id;
var $result = array("" => "");
function pagina () // constructor
{
$db = new database();
$db->uitvoeren("select * from pagina");
while ($row = $db->uitlezen())
{
$user = $row[0];
echo "<a href=\"page.php?id=$row[id]\">$row[achternaam]</a><br>";
}
if(isset($_GET[id]))
{
$this->update();
}
if($_POST[submit] = "opslaan")
{
$this->opslaan();
}
$this->weergeven();
}
function opslaan ()
{
$db = new database();
$db->uitvoeren("update pagina set content='$_POST[content]' where id='$_POST[id]'");
}
function update()
{
$obj_database=new database();
$obj_database->uitvoeren ("select * from pagina where id=$_GET[id]");
$this->result = $obj_database->uitlezen();
}
function weergeven () // functie weergeven aanmaken
{
$obj_template=new template;
$obj_template->inlezen("cms/tpl/pagina.htpl");
$obj_template->vullen($this->result);
$obj_template->tonen();
}
}
$pagina = new pagina ();
?>
_________________________________



Template Class

_________________________________

<?php
class template //klasse template aanmaken

{
var $tpl; //variabel tpl aanmaken
function inlezen($bestand) //functie inlezen aanmaken waarbij het bestand variabel is

{
$fp=fopen($bestand, "r"); //het variabele bestand openen
$this->tpl=fread($fp, filesize ($bestand)); //bestand inlezen

fclose($fp); //bestand sluiten
}
function vullen($varray) //functie vullen aanmaken waarbij varray variabel is

{
foreach($varray as $key => $value)
$this->tpl=str_replace ("<#$key#>", $value, $this->tpl);
} //key aanmaken voor de vervanging met varray
function tonen() //functie tonen aanmaken
{
echo $this->tpl; //weergeven van tpl
}
}
?>
__________________________________


I want to replace: <#Firstname#> <#Lastname#> by "nothing". (A space or something ?...)

Thank you in advance

Greetings,
Troy

pyro
11-21-2003, 07:34 AM
Something like this should work, though I definitely prefer PCRE (http://us2.php.net/manual/en/ref.regex.php). Anyway, here it is with POSIX:

<?PHP

$str = "<#Firstname#> foo <#Lastname#>";

$str = ereg_replace("<#Firstname#>", "", $str);
$str = ereg_replace("<#Lastname#>", "", $str);

echo $str;

?>

DaiWelsh
11-21-2003, 08:36 AM
Originally posted by pyro
though I definitely prefer PCRE (http://us2.php.net/manual/en/ref.regex.php).

Amen

troy1984
11-24-2003, 01:43 AM
Thanks a lot guys,
Is it also possible to hide a textbox using this or the PCRE method??

Thanks in advance

Greetings,
Troy

pyro
11-24-2003, 08:04 AM
What do you mean by "hide a textbox"?

troy1984
11-25-2003, 04:02 AM
I have a input field (textbox) Wich appears all the time. I only want it to apear if you click on my "edit" link. But im not at home rigtht now i'll upload the file tomorrow somewhere. Tnx for all the help Pyro..

Greetings

pyro
11-25-2003, 09:25 AM
Still not sure what you want. For PHP to be able to do this, you will have to send a request to the server. If you want it to happen seemlessly, you'll want to use JavaScript.

troy1984
11-26-2003, 01:44 AM
This are my files.
When you open page.php you see a "menu" in plain tekst links. When I click them the first and last name of a person appears and he or she can edit their content. It's very basic I'm just starting to learn php... My problem: When I open the page the texbox already stands there... I do not want this to happen. I want the texbox only to appear when it's gonna be used. So only if i click on one of the names from the list.

Thanks in advance

Greetings,
Troy

Sexay_Hamster
11-26-2003, 09:10 AM
well if u make the persons name a submit button you could do this

if (!isset($_POST['button'])); {

before everything u want to show up right away and then:

if (isset($_POST['button'])); {

around everything u want to show up after u click

pyro
11-26-2003, 10:00 AM
troy1984 - That is better suited for JavaScript, as PHP runs server-side, and the only way to make any changes would be to send a request to the server.

Sexay_Hamster - You have a semi-colon after your if statement. I think you meant:

if (isset($_POST['button'])) {

troy1984
11-27-2003, 02:00 AM
Ok thanks for replying guys..
I'll try what you just told me.

Greetings,
Troy