php code not working from php str_replace function inside - php

i want run php code inside str_replace();
examples:
data example is here:
"file":"https://example.com/hls2/02/00008/,kioaker9jwxw_n,.urlset/master.m3u8%22,%22id%22:%22kioaker9jwxw"}
My php code example:
$replace1 = str_replace('"file":"', '"file":"https://otherdomain.com/palx/test/?v=\<?php echo base64_encode("', $data);
$replace2 = str_replace('m3u8', 'm3u8")?\>', $replace1);
Edit;::::
i want change "example.com/m3u8" to other.com/ex.php?v=example.com/m3u8 but base64 encoded from data.
data contains one more links.
And contains tokens so changing file to file.
i can't touch /hls2/02/.... because changing file to file, this is auto bot.

Related

how to get the content of another php file without execution? [duplicate]

How to read a .php file using php
Let's say you have two files a.php and b.php on same folder.
Code on the file b.php
<?php
echo "hi";
?>
and code on a.php
<?php
$data = file_get_contents('b.php');
echo $data;
You access a.php on browser.
What do you see? A blank page.
Please check the page source now. It is there.
But not showing in browser as <?php is not a valid html tag. So browser can not render it properly to show as output.
<?php
$data = htmlentities(file_get_contents('b.php'));
echo $data;
Now you can see the output in browser.
If you want to get the content generated by PHP, then
$data = file_get_contents('http://host/path/file.php');
If you want to get the source code of the PHP file, then
$data = file_get_contents('path/file.php');
Remember that file_get_contents() will not work if your server has *allow_url_fopen* turned off.
//get the real path of the file in folder if necessary
$path = realpath("/path/to/myfilename.php");
//read the file
$lines = file($path,FILE_IGNORE_NEW_LINES);
Each line of the 'myfilename.php' will be stored as a string in the array '$lines'.
And then, you may use all string functions in php. More info about available string functions is available here: http://www.php.net/manual/en/ref.strings.php

Read a .php file using php

How to read a .php file using php
Let's say you have two files a.php and b.php on same folder.
Code on the file b.php
<?php
echo "hi";
?>
and code on a.php
<?php
$data = file_get_contents('b.php');
echo $data;
You access a.php on browser.
What do you see? A blank page.
Please check the page source now. It is there.
But not showing in browser as <?php is not a valid html tag. So browser can not render it properly to show as output.
<?php
$data = htmlentities(file_get_contents('b.php'));
echo $data;
Now you can see the output in browser.
If you want to get the content generated by PHP, then
$data = file_get_contents('http://host/path/file.php');
If you want to get the source code of the PHP file, then
$data = file_get_contents('path/file.php');
Remember that file_get_contents() will not work if your server has *allow_url_fopen* turned off.
//get the real path of the file in folder if necessary
$path = realpath("/path/to/myfilename.php");
//read the file
$lines = file($path,FILE_IGNORE_NEW_LINES);
Each line of the 'myfilename.php' will be stored as a string in the array '$lines'.
And then, you may use all string functions in php. More info about available string functions is available here: http://www.php.net/manual/en/ref.strings.php

PHP txt File Manipulations

I'm trying to create a simple one page php website that does the following.
Displays data from a txt file and then converts it into links.
(A line from the text file would be so if the line is "TextEdit: 1.9" ApplicationName = TextEdit)
So basically I need to add the url strings together with the application names in the desired locations and then redirect to that page. Hopefully ending up with something like:
Link[urlportion+appname+urlportion]
I am getting my data from a txt file that is formatted in the format of:
TextEdit: 1.9
AppleScript Editor: 2.6
Arduino: 1.0.5
TextWrangler: 4.5.3
etc.
I can display the code in my page using:
<?php
foreach(glob("log.txt") as $filename) {
$file = $filename;
$contents = file($file);
$string = implode("<br>",$contents);
echo $string;
echo "<br></br>";
}
?>
That works beautifully my question is how do I separate the txt file into pieces so I can concatenate it with my url and display it.
If it's simple you can just use a text file and delimit your strings. You're going to need a server-side technology to do this - PHP, ASP.NET, etc. You haven't posted what your server-side technology is, but this can't be done without it.

pass mysql value from php page to a joomla article and display relevant data inside of a joomla article

we are developing an application.website is being developed by joomla.Admin panel is being developed using a pure php.on index page(joomla), we are displaying some details from the backend.
my question is this, when we click on one of the records on that page can we display the relevant data inside of a article?
Hope i asked the question clearly.
please share your thoughts with us.
thanks in advance
Yes, you can do this, if I understand your question correctly.
Open up Joomla's main index.php. This is the index.php in the html root, not the index.php in one of the template folders.
Near the bottom of the file, or maybe the very last line you will see something like this:
// Return the response.
echo $app
Replace this line with the following:
// Return the response.
// parse $app for server side includes statements and execute them
// note: this will only work for executable code, it will not import text or html files
// we would need to check to see if the file were executable, then read it rather than execute it if it were not
$output = $app;
while(ereg('(<!--#include virtual="([^&]+)" -->)',$output,$groups)){ // extract the ssi command and the command
$i = 0;
while(!$inline){ // sometimes exec() fails for want of memory so we try a few times
exec($groups[2],$array); // get the output from the command
foreach ($array as $element) // concatenate the lines of output into a single string
$inline = $inline . $element . "\n"; // appending a new line makes the html source more readable
$i++;
if($inline | $i > 5)
break;
sleep(1);
}
$output = ereg_replace($groups[1],$inline,$output); // replace the ssi command with the output
}
echo $output;
This will allow you to place a standard server side includes statement in your article. Fore example if you want to execute a php file in the same directory as your index.php and the file is called dynamic_content.php you would type this in your article:
<!--#include virtual="dynamic_content.php"-->
The output of that script will then be included in the text of the article. You can have multiple ssi commands in the same article.

How to replace text file data with form using php?

I've a text file.Now i want to replace text data with a form (POST or GET) in PHP.
My text file like that-
"
Mr.A
87362
Mr.B
87427
Mr.C
85423
"
Now if i want to change Mr.A to Mr.H with a form submit POST or GET method,what should i do?
Whenever yo have to change a text file, you always have to read it into memory, do string manipulation and write the whole thing to a file again.
This explains a lot Overwrite Line in File with PHP
Assuming you can get your variables from your POST request, you should be able to follow the solution in the above link to help solve your problem.
here is the code
<?php
$n="filename.txt";
$f=fopen($n,'r');
$c=fread($f,100);
$final = str_replace("Mr.A ", "Mr.".$_POST['field'], $c);
fclose($f);
$f=fopen($n,'w');
fwrite($f,$final);
fclose($f);
?>

Categories