Jump to content


Photo

Removing part of text


  • Please log in to reply
2 replies to this topic

#1 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 15 September 2006 - 02:25 PM

Hi,

Im pulling a string (/maindir/subdir/index.php) from a database but need to remove the /maindir bit and leave with the rest, the code Iv got is just leaving me with index.php - any ideas? In another part of the site, I need to add /maindir to the beggining - also any ideas?

Many thanks

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 15 September 2006 - 02:35 PM

if you're wanting to remove the "/maindir" from the front of a string, just do this:
<?php
$String = "/maindir/subdir/index.php";
$String = preg_replace('|^/maindir|', '', $String);
echo $String;
?>

if you're wanting to add it, just concatonate your string:
<?php
$String = "/subdir/index.php";
echo "/maindir" . $String;
?>

hope this helps
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 matfish

matfish
  • Members
  • PipPipPip
  • Advanced Member
  • 242 posts
  • LocationUK

Posted 15 September 2006 - 02:40 PM

Brilliant - thank you once again!

Deffo a super-guru ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users