Jump to content


Photo

Need help with str_replace


  • Please log in to reply
2 replies to this topic

#1 sgerbitz

sgerbitz
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 13 April 2006 - 04:47 PM

Attached is my code.

I am trying to replace the [br] with <br> in my summary section of this page. I am confused, I thought I had ti right.. there must be a typo somewhere

<?PHP
 session_start();
 require("access.php");
 ?>

<?php include("top2.php"); ?>


<?php 
$query = mysql_query("SELECT * FROM `users` where USERNAME = '" . $_SESSION[UserName] . "'") or die ("Error: " . mysql_error());
$data = mysql_fetch_array($query);
?>

<table width="83%" height="486" border=0 cellpadding=2 cellspacing=0>
  <tr>
    <td height="23" colspan="2"><div align="left"><b> </b></td>
  </tr>
  <tr>
    <td width="49%">      <blockquote>
      <div id="Layer1" style="position:absolute; width:200px; height:115px; z-index:1; left: 219px; top: 233px;">
        <div align="center"><img src="<?php if ($data['PHOTO_URL']) { echo $data['PHOTO_URL']; } else { echo './images/no_pic.gif'; }?>" width="150" height="150" border="0" alt="<?php if ($data['USERNAME']) { echo $data['USERNAME']; } else { echo 'no photo'; }?>" />
            </p>
          </div>
      </div>
      <div id="Layer4" style="position:absolute; width:292px; height:23px; z-index:4; left: 338px; top: 192px;">
        <div align="center">
          <h3><span style="font-weight: bold">Your Current Profile</h3>
        </div>
      </div>
    </blockquote>
    </td>
    <td width="51%"><div id="Layer2" style="position:absolute; width:329px; height:139px; z-index:2; left: 155px; top: 388px;">
        <p><strong>Username:</strong> <?=$data['USERNAME']?>
            <strong><br />Gender:</strong> <?=$data['GEN']?>
            <strong><br />Country:</strong> <?=$data['COUNTRY']?>
            <strong><br />State:</strong> <?=$data['STATE']?>
            <strong><br />Year of Birth:</strong> <?=$data['BIRTH']?>
            <strong><br />Email:</strong> <?=$data['EMAIL']?>
            <strong><br />Last Update:</strong><?=$data['MONTH']?>/<?=$data['DAY']?>/<?=$data['YEAR']?> -- <?=$data['TIME']?>
        </p>
        </div>      
      <p align="justify"> </p>
      <div id="Layer3" style="position:absolute; width:342px; height:347px; z-index:3; left: 508px; top: 219px;">
        <p><b>My Summary:</b></p>
        <p>

<?php
$SUMMARY = str_replace('[','<',$data['SUMMARY']);
$SUMMARY = str_replace(']','>',$data['SUMMARY']);
echo $data['SUMMARY'];
?>

    </p>
        <p> </p>
        <p> </p>
      </div></td></tr>
</table>

<?php include("bottom2.php"); ?>


#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 13 April 2006 - 05:25 PM

I guess this si the code you're using to convert [br] tp <br>?
$SUMMARY = str_replace('[','<',$data['SUMMARY']);
$SUMMARY = str_replace(']','>',$data['SUMMARY']);
If so change it to:
$SUMMARY = str_replace("[br]", "<br />", $data['SUMMARY']);
Also why are you using [br] why not just hit enter to add a new line in your textarea, then use nl2br when you retrieve the data out of the database instead? Makes life so much easier.

#3 sgerbitz

sgerbitz
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 13 April 2006 - 05:30 PM

[!--quoteo(post=364493:date=Apr 13 2006, 12:25 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Apr 13 2006, 12:25 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
I guess this si the code you're using to convert [br] tp <br>?
$SUMMARY = str_replace('[','<',$data['SUMMARY']);
$SUMMARY = str_replace(']','>',$data['SUMMARY']);
If so change it to:
$SUMMARY = str_replace("[br]", "<br />", $data['SUMMARY']);
Also why are you using [br] why not just hit enter to add a new line in your textarea, then use nl2br when you retrieve the data out of the database instead? Makes life so much easier.
[/quote]


its just an example, like [b] [u] ... I am trying to allow only a couple of html codes to be used in my registration script.

Could you help me fix the issue?

oops I didnt read the whole response...

$SUMMARY = str_replace("[br]", "<br />", $data['SUMMARY']);

I tried that, and it still doent work.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users