PHP strings replace in a file [duplicate] - php

This question already has answers here:
Redefining constants in PHP
(5 answers)
Closed 8 years ago.
I have a php file like this.
define('TEXT_ONE', 'testvalue1');
define('TEXT_TWO', 'testvalue12');
define('TEXT_THREE', 'testvalue13');
define('TEXT_FOUR', 'testvalue14');
define('TEXT_FIVE', 'testvalue15');
define('TEXT_SIX', 'testvalue16');
define('TEXT_SEVEN', 'testvalue17');
define('TEXT_EIGHT', 'testvalue18');
define('TEXT_NINE', 'testvalue19');
define('TEXT_TEN', 'testvalue10);
define('TEXT_ELEVEN', 'testvalue11');
I want to change some of the defined value through php code.
for ex:- I Want to change above file to
define('TEXT_ONE', 'newtext1');
define('TEXT_TWO', 'newtext12');
define('TEXT_THREE', 'newtext13');
define('TEXT_FOUR', 'newtext14');
define('TEXT_FIVE', 'newtext15');
define('TEXT_SIX', 'newtext16');
define('TEXT_SEVEN', 'newtext17');
define('TEXT_EIGHT', 'newtext18');
define('TEXT_NINE', 'testvalue19');
define('TEXT_TEN', 'newtext10);
define('TEXT_ELEVEN', 'testvalue11');
Can any one help me?
Thanks

define — Defines a named constant.
As the name suggests, that value cannot change during the execution of the script

Related

how do I make a php variable successfully available in another php file? [duplicate]

This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 2 years ago.
I have 2 php files inside joomla and I want to make a variable from php-file 1 available in php-file 2.
php-file_1.php
$a_variable = $input->getString('text');
php-file_2.php
include(php-file_1.php);
echo $a_variable;
I get Notice: Undefined variable: a_variable in /var/www/vhosts/a_domain.de/httpdocs/php-file_2.php on line 2
what's wrong here?
include and require are not functions, they are language constructs. Therefore they need to be used without brackets.
Either way, you missed quotes around php-file_1.php.
include 'php-file_1.php'; should work fine.

Dynamic prefix attribute PHP [duplicate]

This question already has an answer here:
How can I access a property with an invalid name?
(1 answer)
Closed 6 years ago.
I have a question about attributes in PHP.
I have various Class with the same attributes, but with with different prefix.
Example:
$attr->a_field;
$attr2->b_field;
So, with another Class I want to access to them.
I tried:
$field = "{$prefix}_field";
$attr->{$field}
and it works perfect. But is any other way to doing this?
I tried also with:
$attr->{$prefix}_field;
$attr->{$prefix}{"_field"};
$attr->"{$prefix}_field";
etc and who I suppose I get PHP's errors
Thanks!
You can write it directly as $attr->{"{$prefix}_field"}, as shown in the docs.
You're looking into variable variables
$attr->{$prefix."_field"}

How to pass variable in PHP using include? [duplicate]

This question already has answers here:
Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors?
(3 answers)
Closed 8 years ago.
I have one page where i need to send some results to another PHP file.
include("test.php");
but i want to pass variable (var) also so that which can be processed by test.php using $_GET['var'] command. How is it possible in PHP?
$var1="hello";
include ("test.php");
the test file contains below code
echo $var1." world";

php variable from variable [duplicate]

This question already has answers here:
Mixing a PHP variable with a string literal
(5 answers)
Closed 9 years ago.
I have a variable and I want to create a variable with that. I get the variable from database and put it together with some text and then I want another variable.
For exampel
$a = $ . "txt" . $d;
Try with this. It will create a variable from another one.
$a = ${'txt'.$d}
P.s. This is a question asked a couple of times. You might have found the answer simply by searching the issue on google.

concatenate wordpress option setting value to css class [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to concatenate echos
I want to concatenate wordpress option setting value (get_option('my_option_value') with css class in php file.
My css class are box-one ,box-two, box-three. While (get_option('my_option_value') gives value one,two and three according to option setting.How can I concatenate class="box-"
and (get_option('my_option_value')?
In your HTML, insert PHP inline with :
class="box-<?php echo get_option('my_option_value'); ?>" ...

Categories