String Replacements For A Textfeild

i need to display html in it

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 2046 Views - Last Post: 17 March 2003 - 08:27 PM Rate Topic: -----

#1 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

String Replacements For A Textfeild

Posted 13 March 2003 - 05:54 AM

ok, the site i am working on for my school will have tutorials and other stuff like that on it. i need to be able to type HTML into the textarea and make it display the code of the HTML when i submit it. so if it is a tutorial on how make text bold and i put <b> </b> in there it will show up like it does here. so i am using string replacements to change < to &lt; and > to &gt; but i also need to have bb code cause of that, so when my teacher or myself add a tut and we need to insert something like a link or a image, the html wont work cause of the string replacements. so how would i do something for a url... this is all the string replacements that i got can you tell me what wont work and how i can make it work.

<?
{
	$row_view['main'] = str_replace("/n", "<br>", $row_view['main']);
	$row_view['main'] = str_replace(" ", "&nbsp;", $row_view['main']);
	$row_view['main'] = str_replace("<b>", "[b]", $row_view['main']);
	$row_view['main'] = str_replace("</b>", "[/b]", $row_view['main']);
	$row_view['main'] = str_replace("<i>", "[i]", $row_view['main']);
	$row_view['main'] = str_replace("</i>", "[/i]", $row_view['main']);
	$row_view['main'] = str_replace("<u>", "[u]", $row_view['main']);
	$row_view['main'] = str_replace("</u>", "[/u]", $row_view['main']);
	$row_view['main'] = str_replace("<img src=", "[img]", $row_view['main']);
	$row_view['main'] = str_replace("> ", "[/img]", $row_view['main']);
	$row_view['main'] = str_replace("<a href=", "[url]", $row_view['main']);
	$row_view['main'] = str_replace("> ", "[/url]", $row_view['main']);
	$row_view['main'] = str_replace("<a href=mailto:", "[email]", $row_view['main']);
	$row_view['main'] = str_replace("> ", "[/email]", $row_view['main']);
}
?>


also is there i way i can make it work with all the pages automaticly cause right now i would have to add this code to everypage cause of the row names and stuff. is there a way i can make it just a include so i can put it in the templete for the site and it includes it on every page automaticly?

Is This A Good Question/Topic? 0
  • +

Replies To: String Replacements For A Textfeild

#2 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 13 March 2003 - 10:20 AM

ok blunted, here's my thoughts on your situation, you're pulling the data from a db, and so therefore, if you program your site correctly, you only need to create one page something like tutorials.php that does a query like

$query = "SELECT * FROM tutorials WHERE id=$id";


and so your links to the tutorials would just be tutorials.php?id=1 or whatever number it needs to be.

and to prevent the hand making of all the links you could do a query on the db to get the tutorial title and id number so that you could do a while loop, well, here, i'll show you:

$query = "SELECT tut_name, id FROM tutorials ORDER BY tut_name ASC";
$result = mysql_query($query) or die($query." failed because: ".mysql_error());

while($row = mysql_fetch_array($result)) {
  extract($row);
?>
  <a href="tutorials.php?id=<?=$id ?>"><?=$tut_name ?></a>
<?
}
?>


ok, so case and point, the above snippet of code will print out your links to the tutorials, when clicked on it goes to the tutorial page, which should contain the first snippet of code i gave you, as well as your posted code for the string replacements.

and thus, you'll have yourself some nice little tutorials...i hope this has helped, if not let me know and i'll try to help you further.
Was This Post Helpful? 0
  • +
  • -

#3 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: String Replacements For A Textfeild

Posted 13 March 2003 - 02:31 PM

well you answered a good part of my questions, just i wasnt sure how i would do the string replacements, i wanted to know if how i was doing the replacements were correct.
Was This Post Helpful? 0
  • +
  • -

#4 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 13 March 2003 - 03:05 PM

BluntedbyNature, on Mar 13 2003, 02:31 PM, said:

well you answered a good part of my questions, just i wasnt sure how i would do the string replacements, i wanted to know if how i was doing the replacements were correct.

ok, so do you want ibtags to convert to html tags or vise versa?
Was This Post Helpful? 0
  • +
  • -

#5 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: String Replacements For A Textfeild

Posted 13 March 2003 - 03:39 PM

i wanna change <b> into [ b] with out the space of course
Was This Post Helpful? 0
  • +
  • -

#6 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: String Replacements For A Textfeild

Posted 13 March 2003 - 03:41 PM

so if i wanted to, i could add HTML into the textarea and not have the browser read it as HTML. cause i would just change < to &lt;
Was This Post Helpful? 0
  • +
  • -

#7 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 13 March 2003 - 04:03 PM

BluntedbyNature, on Mar 13 2003, 03:39 PM, said:

i wanna change <b> into [ b] with out the space of course

that being the case, you're str_replace statements are correct...
Was This Post Helpful? 0
  • +
  • -

#8 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: String Replacements For A Textfeild

Posted 14 March 2003 - 06:12 AM

its not working!!! stupid php!!
this is my source
<?php require_once('Connections/conn.php'); ?>
<?php
mysql_select_db($database_conn, $conn);
$query_cs1_2 = "SELECT * FROM cs1_2 ORDER BY id DESC";
$cs1_2 = mysql_query($query_cs1_2, $conn) or die(mysql_error());
$row_cs1_2 = mysql_fetch_assoc($cs1_2);
$totalRows_cs1_2 = mysql_num_rows($cs1_2);
?>
 
<HTML><!-- InstanceBegin template="/Templates/index.dwt.php" codeOutsideHTMLIsLocked="false" -->
<HEAD>
<!-- InstanceBeginEditable name="doctitle" -->
<TITLE>Lindenhurst High School Computer Science Department</TITLE>
<!-- InstanceEndEditable --> 
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<link href="styles.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable --> 
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<TABLE WIDTH=100% BORDER=0 align="center" CELLPADDING=0 CELLSPACING=0>
  <TR> 
    <TD COLSPAN=2 background="images/index_03.gif"><img src="images/index_01.gif" width="143" height="85"> 
    </TD>
    <TD COLSPAN=4 background="images/index_03.gif"><img src="images/index_02.gif" width="301" height="85"> 
    </TD>
    <TD COLSPAN=4 background="images/index_03.gif">&nbsp; </TD>
  </TR>
  <TR> 
    <TD background="images/index_11_bg.gif"> <a href="index.php"><IMG SRC="images/index_04.gif" ALT="" WIDTH=56 HEIGHT=29 border="0"></a></TD>
    <TD COLSPAN=2 background="images/index_11_bg.gif"> <a href="cs1_2.php"><IMG SRC="images/index_05.jpg" ALT="" WIDTH=100 HEIGHT=29 border="0"></a></TD>
    <TD background="images/index_11_bg.gif"> <a href="cs3_4.php"><IMG SRC="images/index_06.gif" ALT="" WIDTH=102 HEIGHT=29 border="0"></a></TD>
    <TD background="images/index_11_bg.gif"> <a href="cs_apa.php"><IMG SRC="images/index_07.gif" ALT="" WIDTH=99 HEIGHT=29 border="0"></a></TD>
    <TD COLSPAN=2 background="images/index_11_bg.gif"> <a href="cs_apab.php"><IMG SRC="images/index_08.gif" ALT="" WIDTH=104 HEIGHT=29 border="0"></a></TD>
    <TD background="images/index_11_bg.gif"> <IMG SRC="images/index_09.gif" WIDTH=111 HEIGHT=29 ALT=""></TD>
    <TD background="images/index_11_bg.gif"> <IMG SRC="images/index_10.gif" WIDTH=99 HEIGHT=29 ALT=""></TD>
    <TD background="images/index_11_bg.gif"> <IMG SRC="images/index_11.gif" WIDTH=89 HEIGHT=29 ALT=""></TD>
  </TR>
  <TR> 
    <TD COLSPAN=10 valign="top"> <br>
      <table width="99%" border="1" align="center" cellpadding="1" cellspacing="0" bordercolor="#000000">
        <tr> 
          <td bgcolor="#339933" class="title"><!-- InstanceBeginEditable name="table_title" --><?php echo $row_cs1_2['title']; ?><!-- InstanceEndEditable --></td>
        </tr>
        <tr> 
          <td valign="top"><br> <table width="95%" border="0" align="center">
              <tr> 
                <td valign="top" class="inner"><!-- InstanceBeginEditable name="main" --> 
                  <?
{
	$row_cs1_2['main'] = str_replace("/n", "<br>", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace(" ", "&nbsp;", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<b>", "[b]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("</b>", "[/b]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<i>", "[i]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("</i>", "[/i]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<u>", "[u]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("</u>", "[/u]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<img src=", "[img]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("> ", "[/img]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<a href=", "[url]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("> ", "[/url]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<a href=mailto:", "[email]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("> ", "[/email]", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace("<", "&lt;", $row_cs1_2['main']);
	$row_cs1_2['main'] = str_replace(">", "&gt;", $row_cs1_2['main']);
}
?>
      <?php echo $row_cs1_2['main']; ?><!-- InstanceEndEditable --></td>
              </tr>
            </table>
            <br> </td>
        </tr>
      </table>
      <br> <br> </TD>
  </TR>
  <TR> 
    <TD height="2"> <IMG SRC="images/spacer.gif" WIDTH=56 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=87 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=13 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=102 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=99 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=87 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=17 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=111 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=99 HEIGHT=1 ALT=""></TD>
    <TD> <IMG SRC="images/spacer.gif" WIDTH=89 HEIGHT=1 ALT=""></TD>
  </TR>
</TABLE>
<div align="right">
  <p class="copy"><br>
    copyright &copy; vinny cerone. 2002-2003. all rights reserved.</p>
</div>
</BODY>
<!-- InstanceEnd --></HTML>
<?php
mysql_free_result($cs1_2);
?>


i can view html in it now, which is a plus, but i need everything else to work! can someone please help me!!!
Was This Post Helpful? 0
  • +
  • -

#9 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 14 March 2003 - 07:47 AM

what do you mean when you say it's not working, is it giving you an error, is it not displaying what you want to see, what's the prob exactly?
Was This Post Helpful? 0
  • +
  • -

#10 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: String Replacements For A Textfeild

Posted 14 March 2003 - 01:38 PM

it not displaying what i want, it shows the BB code instead of using the BB code.
Was This Post Helpful? 0
  • +
  • -

#11 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 15 March 2003 - 09:07 AM

can i have the url, so that i can see this?

because i'm confused, i wasn't aware that you had hacked an ibforum to make it work with tutorials, are you trying to do what sloth did with dreamincode, because perhaps if you asked him, he'd share his code with you, because i know that as long as you're not going to take the code and run, i think he'll share it with you, because it is for a good purpose...
Was This Post Helpful? 0
  • +
  • -

#12 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 15 March 2003 - 09:17 AM

infact, here

Quote

i'm fine with letting people know how the site works and even give them the code so they can do it (just ask blunted) the only thing is the person must have really legitimate reasons. our job isn't to give the code away to competitors or to generate lots of copy cat sites.


that's a quote from sloth, i got it from this thread.
Was This Post Helpful? 0
  • +
  • -

#13 iamcenz  Icon User is offline

  • You wish you were my hand!
  • member icon

Reputation: 7
  • View blog
  • Posts: 2,442
  • Joined: 26-March 01

Re: String Replacements For A Textfeild

Posted 15 March 2003 - 09:53 AM

no i didnt hack a ibforum, its just pretty much bb code. i just want it so i can display html code in the text area, but for me to do that i got to change the html codes that i use, like <b></b>, and <i></i> and <a href=""></a> to bb code so that it wont display the html for on the page.
Was This Post Helpful? 0
  • +
  • -

#14 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 15 March 2003 - 10:03 AM

i'm so confused by what you're trying to do...

i think i have a script that you would like, so, first, let me ask a question, you want to display the html not 'execute' it? (i know execute isn't the right word, but i couldn't think of the proper one.)
Was This Post Helpful? 0
  • +
  • -

#15 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: String Replacements For A Textfeild

Posted 15 March 2003 - 10:21 AM

just so you can see what i'm talking about, i'll give you the link:

click here

it's kindof like the php function show source, but it's for html
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2