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
Link to comment
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;
Link to comment
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
Link to comment
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]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.