0

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

6
Contributors
8
Replies
9
Views
4 Years
Discussion Span
Last Post by diafol
0
<?php
$myString = "USA";
echo $myString;
echo "<h5>I am going to</h5>";
?>

Thank you,

Edited by diafol: This is a fake sig - please refrain

0

You can get your required output through

<?php
function country()
{
echo "USA";
}
echo "i am going to [".$country."]";
?>

Hope this helps you.

0

@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

0

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.

Edited by diafol

0

Wow, I did not know there is that much possibility?

But I may be wrong

I do not know either.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.