chmpdog Posted December 3, 2008 Share Posted December 3, 2008 Hola, In my script I have a variable, and I need to echo it. But here is the tricky part. I need to echo it in a certain place in a paragraph, which is taken from MySql. So, does anyone know how to do this? Thankyou Quote Link to comment Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 I am a little confused. Let me try to clarify. You have a paragraph (i will use a sentence for example sake): "Hello my name is Name!" and you want to put some one's name in there? Quote Link to comment Share on other sites More sharing options...
haku Posted December 3, 2008 Share Posted December 3, 2008 Elaborating on that: $name = 'John'; $paragraph = 'My name is NAME'; $formatted_paragraph = str_replace('NAME', $name, $paragraph); Quote Link to comment Share on other sites More sharing options...
chmpdog Posted December 3, 2008 Author Share Posted December 3, 2008 Im pretty sure that will work... Thanks Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 I am sure this will do the same try it mate....... <?php $sql="select SUBSTRING(field_name,-4) from table_name"; $res=mysql_query($sql)or die(mysql_error()); ?> Quote Link to comment Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 I am sure this will do the same try it mate....... <?php $sql="select SUBSTRING(field_name,-4) from table_name"; $res=mysql_query($sql)or die(mysql_error()); ?> that is assuming my example was what he actually needed. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 3, 2008 Share Posted December 3, 2008 Uhm.... What?! Edit: That was at redarrow. Also, it wouldn't work alone because he would have to concatenate the name (or whatever) to the end. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 say in the database you had "my name is john" why wouldnt it just echo john from the field name from the database........ <?php $sql="select SUBSTRING(name,-4) from text where id='$session_id'"; $res=mysql_query($sql)or die(mysql_error()); while($rec=mysql_fetch_assoc($rec)){ echo " ".$rec["name"]." "; } ?> Quote Link to comment Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 yeah but if the name is changing frequently, then it woulnt work. Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 u can use REGEXP in the select statement, to show the word afther the 3rd space in the database field and that word can be any size......... Quote Link to comment Share on other sites More sharing options...
dclamp Posted December 3, 2008 Share Posted December 3, 2008 Well still, you are basing your code off of my example. The OP stated that there is a paragraph and he needed to change something within the paragraph. The easiest solution is str_replace() Quote Link to comment Share on other sites More sharing options...
redarrow Posted December 3, 2008 Share Posted December 3, 2008 Agree sorry......... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.