Jump to content

Archived

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

seaten

using ereg_replace(with variable stored in string)

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

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
[!--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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.