Jump to content

using ereg_replace(with variable stored in string)


seaten

Recommended Posts

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
[!--quoteo(post=351046:date=Mar 2 2006, 01:47 PM:name=dcro2)--][div class=\'quotetop\']QUOTE(dcro2 @ Mar 2 2006, 01:47 PM) [snapback]351046[/snapback][/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
Slight alteration from:
$theData = ereg_replace('<b>', '<b> $person_name', $theData);

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

Example:
[code]<?php

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

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

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.