Page 1 of 1

i give up

Posted: Fri Mar 12, 2004 7:06 pm
by tim
this is simple I know but i must be dumb or having a brainfreeze.

Maybe i'm going about it all wrong, but after seeing everyones attempt at a boocde, i have something like this:

Code: Select all

<?php
function code($string) { 
$old = array('[ b ]', '[ /b ]'); //I have spaces in between cause the board dont display it correctly
$new = array('<b>', '</b>'); 
?>
I tried foreach to loop a form textarea but I get nothing

how would I create a foreach loop using ereg_replace to transfer the code to html tags from the old array -> new? I give up
=[

Posted: Fri Mar 12, 2004 7:35 pm
by angrytuna
Something like this?

Code: Select all

<?php
$old = array('[ b ]', '[ /b ]');
$new = array();
foreach ($old as $value){
	print "old value: $value<br />";
	$value = ereg_replace("\[","<",$value);
	$value = ereg_replace("\]", ">", $value);
	print "new value: $value<br />";
        array_push($new, $value);
}
?>

Posted: Fri Mar 12, 2004 7:36 pm
by Illusionist
just use str_replace()

Code: Select all

$old = array('[ b ]', '[ /b ]'); //I have spaces in between cause the board dont display it correctly
$new = array('<b>', '</b>');
$text = "[ b ]Sup?[ /b ]";
echo str_replace($old,$new,$text);

Posted: Fri Mar 12, 2004 7:47 pm
by tim
well I wanted to make it a function so I can use it on a textarea that will be inserted to mysql and called upon to be displayed on a page (like a blog type deal)

this is what i'm using for testing purpose (now using the str_replace with no loop):

Code: Select all

<?
function code($string) {
$old = array('[ b ]', '[ /b ]'); 
$new = array('<b>', '</b>'); 
str_replace($old,$new,$string); 
}


echo "<form action=$PHP_SELF method=GET><textarea size=40 name=msg></textarea><br>";
echo "<input type=submit value=submit></form>";
echo "<br>$msg";

?>
whats the obvious thing i'm missing? is there a better/easier approach? i'm not really good with expressions and I do not understand them well.

Posted: Fri Mar 12, 2004 7:51 pm
by Illusionist
your not calling that function... where you have <br>$msg, try cahnging it to <br>code($msg) and see if that works!

Posted: Fri Mar 12, 2004 7:56 pm
by tim
i have that in my code (i pasted the code with str_replace n forgot to update it)

still a no-go using the above code

Posted: Fri Mar 12, 2004 8:00 pm
by Illusionist
show your whole code

Posted: Fri Mar 12, 2004 8:04 pm
by tim

Code: Select all

<? 
function code($string) { 
$old = array('[ b ]', '[ /b ]'); // without the spaces surrounding the b's
$new = array('<b>', '</b>'); 
str_replace($old,$new,$string); 
} 


echo "<form action=$PHP_SELF method=GET><textarea size=40 name=msg></textarea><br>"; 
echo "<input type=submit value=submit></form>"; 
echo code($msg);
?>
this outputs nothing.

Posted: Fri Mar 12, 2004 8:11 pm
by Illusionist
str_replace($old,$new,$string); to return str_replace($old,$new,$string);

Posted: Fri Mar 12, 2004 8:16 pm
by tim
that was the key to the puzzel...

one of those days. at the shop today I caught my carhartts on fire, lost my $60 dollar wire stripping tool and managed to get nothing accomplished. I knew better to attempt to fix any code

thanks

Posted: Fri Mar 12, 2004 8:17 pm
by Illusionist
LOL, i can't say that that has ever happened before!

Posted: Fri Mar 12, 2004 8:31 pm
by tim
it was/is pure horror. the carhartts overalls are okay (thank god cause they were over 100 bucks.) I was burning body clamps under a bus so we can lift the body and I didnt feel it but i smelt the smoke (when your burning your focusing on the object your burning, if you look away you cant see where the tip of the torch is and can fire a load of hot cherries/sparks right at you)... u can tell where they were burned. who knows what happened to my wire tool (that was my baby) and I hope to find it tomorrow. Before I started this script code, I spent about an hour finding a stupid active-x installed program (called internet optimizer) and all its components to 100% get rid of it.

i tell you, i would be better off staying in bed all day today with a huge bucket beside me to pee in.

Posted: Fri Mar 12, 2004 8:33 pm
by Illusionist
lol, sounds like a pretty bad day! I HAVE had lots of those myself!! And most tiems i do feel like staying in bed ALL day...

o well!