Jump to content


Photo

Replacing part of a string


  • Please log in to reply
2 replies to this topic

#1 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 27 January 2006 - 03:32 AM

I'm using str_ireplace to replace parts of a string, which works fine for the most part, but it always outputs the replaced text on a new line.
This is what I'm doing. $newspost is the string, and $searchnews is the string being replaced.
	if($_POST['hilite'] == 'on' && $searchnews !== '')
	{
		$newspost = str_ireplace($searchnews, '<div id="highlight">' . $searchnews . '</div>', $newspost);
	}
	echo $newspost;

The only thing I've set for #highlight is "background-color: #605555"... :sleep:

Also, is there any way to make sure that the replacement isn't made inside, for instance, a div tag?

Edited by DeathRay2K, 27 January 2006 - 03:34 AM.


#2 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 27 January 2006 - 05:18 AM

You would want to use a <span> rather than a <div>. <div> is a block level element and behaves like a table and will force linebreaks unless you specify a different display style. <span> is for inline formatting.
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#3 DeathRay2K

DeathRay2K
  • Members
  • 96 posts
  • Location:Canada
  • Projects:D2K Studios, Xaeon Mod, Unseen Presence, Rhythm Mixer, Website Designs, CSS OS

Posted 27 January 2006 - 03:00 PM

Thank you very much, that has fixed both of my problems. :lol:
Still, I've never experienced a div acting like that before...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users