Jump to content


Photo

using ereg_replace(with variable stored in string)


  • Please log in to reply
3 replies to this topic

#1 seaten

seaten
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 March 2006 - 06:42 PM

Hi guys,



I'm trying to replace a stringA with stringB(this has a variable in it)

$theData = ereg_replace('<b>', '<b> $person_name', $theData);
echo $theData;


The problem is : '<b> $person_name'

The value of $person_name is not displayed, so what do I need to add to display the value of the variabe ?

Regards and thanks in advance

#2 dcro2

dcro2
  • Members
  • PipPipPip
  • Advanced Member
  • 489 posts

Posted 02 March 2006 - 06:47 PM

Hi there,
In order for PHP to parse (add the actual value of the var) you need double quotes around it:

$theData = ereg_replace('<b>', "<b> $person_name", $theData);
echo $theData;

OR:

$theData = ereg_replace('<b>', '<b> '.$person_name, $theData);
echo $theData;

#3 seaten

seaten
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 02 March 2006 - 06:55 PM

[!--quoteo(post=351046:date=Mar 2 2006, 01:47 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Mar 2 2006, 01:47 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi there,
In order for PHP to parse (add the actual value of the var) you need double quotes around it:

$theData = ereg_replace('<b>', "<b> $person_name", $theData);
echo $theData;

OR:

$theData = ereg_replace('<b>', '<b> '.$person_name, $theData);
echo $theData;
[/quote]


thanks a million

#4 khburres

khburres
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 02 March 2006 - 07:00 PM

Slight alteration from:
$theData = ereg_replace('<b>', '<b> $person_name', $theData);

to:
$theData = ereg_replace('<b>', '<b> ' . $person_name, $theData);

Example:
<?php

$person_name = "Billy";
$theData = "<b> is great";

$theData = ereg_replace('<b>', '<b> ' . $person_name, $theData);
echo $theData;

?>


He who guards his mouth and his tongue keeps himself from calamity.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users