Get some text with CURL and parse only the variables inside with PHP -
php getting external text variable curl domain like: https://somedomain.com/file.txt
this file.txt contains text , variables inside like:
welcome our $storename store, $customername
our store located @ $storeaddress in somewhere.
you see text contains variables inside.
when text in php file in domain like: https://example.com/emailer.php
this emailer.php file is:
<?php # defining variables use in text acquire: $storename = "candy"; $customername = "william"; $storeaddress = "123 store street"; # text domain: $curl = curl_init(); curl_setopt($curl, curlopt_url, "https://somedomain.com/file.txt"); curl_setopt($curl, curlopt_returntransfer, true); $result = curl_exec($curl); echo "$result";
actual result:
welcome our $storename store, $customername
our store located @ $storeaddress in somewhere.
expected result:
welcome our candy store, william
our store located @ 123 store street in somewhere.
how php parse variables, not treat them text?
and without using functions eval() or without enabling remote include "allow_url_include" or without regex or without explode break text , re-merge...
your best option use str_replace in situation, this:
<?php $storename = "candy"; $customername = "william"; $storeaddress = "123 store street"; $result = 'welcome our $storename store, $customername<br> our store located @ $storeaddress in somewhere.'; $result = str_replace( array('$storename','$customername','$storeaddress'), array($storename,$customername,$storeaddress), $result ); echo $result;
Comments
Post a Comment