how can we make Function in php
this is the line to be read = 'i am going to [USA]'
only required the USA to be print nothing else
Please help
@raj-uk
Did you read this:
http://php.net/manual/en/language.functions.php
<?php
function Country()
{
echo "USA";
}
echo "I am going to ";
Country();
?>
<?php
$myString = "USA";
echo $myString;
echo "<h5>I am going to</h5>";
?>
Thank you,
You can get your required output through
<?php
function country()
{
echo "USA";
}
echo "i am going to [".$country."]";
?>
Hope this helps you.
@EmilyJohnson that could not possibly work.
Try avoiding outputting variables in functions, but, return them:
<?php
function country($country)
{
return $country;
}
echo "i am going to " . country("USA") . "<br />";
?>
i am going to USA
how can we make Function in php
this is the line to be read = 'i am going to [USA]'
only required the USA to be print nothing else
Please help
The way I read this is that he wants to strip out USA from the sentence and return that.
<?php
$txt = "I'm off to the [USA]";
preg_match("/\[(.*)\]/",$txt,$match);
$country = $match[1];
echo $country;
?>
But I may be wrong.
Wow, I did not know there is that much possibility?
But I may be wrong
I do not know either.
diafol, you are a STAR..... thank you
Shucks. If that's it, please mark as solved. :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.