ctrenks Posted March 30, 2007 Share Posted March 30, 2007 I am storing text in a blob in SQL, then generating the variable values in code then bringing up the text, the text however shows blank where the variable are although en echo after the text display will show the var displayed correctly. heres an example. Stored text : This is a test to show the variable <? echo $variable ?>, if this works it should be displayed as below. I set $variable="test"; echo the stored text and i get This is a test to show the variable , if this works it should be displayed as below. when I want to see This is a test to show the variable test, if this works it should be displayed as below. TY! Link to comment https://forums.phpfreaks.com/topic/44955-storing-text-with-variables-to-be-called-when-text-is-used-in-a-db-issues/ Share on other sites More sharing options...
spfoonnewb Posted March 30, 2007 Share Posted March 30, 2007 Not sure if I am the only one, but I am having a really hard time understanding what it is you are trying to do. ??? <?php $q = mysql_query("SELECT * FROM test") while($row = mysql_fetch_array( $q )) { $var = $row["mysql_table_row"] echo $var; } ?> Link to comment https://forums.phpfreaks.com/topic/44955-storing-text-with-variables-to-be-called-when-text-is-used-in-a-db-issues/#findComment-218266 Share on other sites More sharing options...
ctrenks Posted March 30, 2007 Author Share Posted March 30, 2007 This seems so simple its confusing! I am storing text in a db, and in that stored text I want to call a variable, so in the text I added <? echo $var ?> so if the variable needs to change i can change it without changing all the stored text. So, I want to display the text on a web page with the current variable data in the spot, not that this is practicle but lets use a date as an example. I store this into the db : Todays date is <? Echo $date_var ?> on my page i want to display it I do this $date_var = $today; $disp_text = "Todays date is <? Echo $date_var ?>"; echo $dsp_text; hoping to get: Todays date is 03/30/2007 Link to comment https://forums.phpfreaks.com/topic/44955-storing-text-with-variables-to-be-called-when-text-is-used-in-a-db-issues/#findComment-218296 Share on other sites More sharing options...
spfoonnewb Posted April 1, 2007 Share Posted April 1, 2007 Here: <?php $today = date("m/d/y"); $date_var = $today; $disp_text = "Todays date is $date_var"; echo $disp_text; ?> Link to comment https://forums.phpfreaks.com/topic/44955-storing-text-with-variables-to-be-called-when-text-is-used-in-a-db-issues/#findComment-218997 Share on other sites More sharing options...
neel_basu Posted April 1, 2007 Share Posted April 1, 2007 If that was your question i hope you have got your answer. Link to comment https://forums.phpfreaks.com/topic/44955-storing-text-with-variables-to-be-called-when-text-is-used-in-a-db-issues/#findComment-219006 Share on other sites More sharing options...
Barand Posted April 1, 2007 Share Posted April 1, 2007 Easiest way is to store "placholder" text in the db text eg <?php $db_text = 'My name is #NAME#. Todays date is #DATE#'; $search = array ('#NAME#', '#DATE#'); $replace = array('ctrenks', date('m/d/Y')); echo str_replace($search, $replace, $db_text); //--> My name is ctrenks. Todays date is 04/01/2007 ?> Link to comment https://forums.phpfreaks.com/topic/44955-storing-text-with-variables-to-be-called-when-text-is-used-in-a-db-issues/#findComment-219034 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.