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

<?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

Member Avatar for diafol

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.

Member Avatar for LastMitch

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

Member Avatar for diafol

Shucks. If that's it, please mark as solved. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.