.php?title=test to echo "test"; - php

I think the title says it all.
I have an URL (example: index.php?title=My title goes here) and I would like to insert the string in my page with echo.
http://mywebsite.com/index.php?title=Alphanumeric title with spaces (if I can't use spaces, I will need to replace any "_" with a space in the final result)
The title is <b><?php echo $title; ?></b>.
The title is Alphanumeric title with spaces.
So, how can I do it?
Thanks in advance.

try with $_GET['title'] you can use space it will decode by urldecode()
The title is <b><?php echo (!empty($_GET['title']) ? urldecode($_GET['title']):''); ?></b>.

$title = urlencode($title); to generate your URL Safe pagination and urldecode($title); for decoding it to a normal string again.

Use $_GET[] for this
$_GET[] is an array containing all data sent through the URL
So in your case, use $_GET['title].
Also remember to use the function isset() to check if the value is actually in the URL!!!

Related

How I have to encode url for Facebook sharing

I am using a JScript code like this:
shareLink = function (link) {
FB.ui({
method: 'share',
display: 'popup',
href: link,
}, function(response){});
}
and it is called in a line like this:
<?php
$sharedata = " ... parameters ... "
?>
<a href="javascript:shareLink('http://<?php echo $site; ?>/?v=<?php echo rawurlencode($sharelink); ?>');">
so, the destination script trasform parameter by using:
$str = rawurldecode($_GET["v"]);
the problem is when the url has a "+" character
using rawurlencode it its converted to "%2B"
zcu0xci%2FFMH2%2B7cLDPVP%2BgD7%2FwQJ%2FFT2Bw%3D%3D
but facebook change only "%2B" into "+" sign again:
zcu0xci%2FFMH2+7cLDPVP+gD7%2FwQJ%2FFT2Bw%3D%3D
and my script does not recognize it
EDIT:
if I echo the "v" parameter I get
zcu0xci/FMH2 7cLDPVP gD7/wQJ/FT2Bw==
instead of
zcu0xci/FMH2+7cLDPVP+gD7/wQJ/FT2Bw==
SOLUTION:
the solution I've found is to replace space by "+" before decode
$str = str_replace(" ","+",$str);
You don't need to use rawurldecode() on elements of the $_GET super-global variable. PHP decodes URL data for you.
In addition, you should generally use urlencode() to encode query string data. If you investigate the difference between these two functions, you'll see that urlencode() will translate any space character to the "+" character. This could possibly be the problem you're experiencing.
I'm having difficulty understanding the remainder of your question. You may need to work on your phrasing.

Passing Variable with space in title how do i

First picture is my code.
I get the Category id "CatID" and Category Title "CatTitle" from the previous page
The results however does not display correctly when there is/are a space/'s in the title. How do i fix this ?
Any help appreciated
Thank you
Sam
you can use urlencode($string) and urldecode($string) functions.
for your case
$catTitle = urldecode($_GET['catTitle']);
%20 shows whenever there is space in URL stirng
The "&" symbol is an example of special character in XML and HTML called entities and must be translated to "&"
Do use the htmlentities funtion to make the translation:
echo htmlentities($CatTitle);
Update: Also consider that the URL may be interpreted as if the $_GET["CatTitle"]="Home " and the $_GET[" Articles"] = null. May be it should be: CatTitle=Home%20&%20Garden in which case you may want to use URL encode while genereting the link.

$_GET didn't not print out # symbol and text behind

i have a string send by $_GET['foo']="C# Programmer";
when I echo $_GET['foo'], it only print C
is any way to solve this problem when string container # or other symbols send by $_GET
Spaces and hashes (#) are not valid in HTTP URLs and will need to be encoded if you want to use it in parameter values. You can use urlencode() to create URL-safe paramter values.
The following should work:
foo=C%23%20Programmer
If you're trying to send the GET request from a different page, you'd want something like this:
<?php
$var = 'C# Programmer';
?>
Go
Now, in select.php, if you try to echo $_GET['foo'];, it'll display C# Programmer.
Make use of functions like urlencode for passing this kind of values, and urldecode to get this values. Try to make use of post method to avoid this kind of problems
You shoud use the function named urlencode which returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.
<?php
$var = 'C# Programmer';
?> <!-- end of PHP code -->
<a href="select.php?foo=
<?php echo urlencode($var) ?> <!-- start and end of PHP code -->
"> Go </a>
Live example
For more information, read about urlencode.

How to Pass a value via href - PHP

Am passing a value using href tag
In first page Href tag used as
echo "$compname";
In the Second page used
$compname = $_GET['compna'];
To receive the Compna values are pass but only the first word is passed remaining words are skipped.
Compname as " Chiti Technologies Ltd "
When I pass the value I receive onlt "Chiti"
The reason you're only getting the first word of the company name is that the company name contains blanks. You need to encode the name.
echo "$compname";
You are producing ambiguous/invalid HTML by not quoting the parameter. The result is something like:
<a href=foo bar baz>
Only foo is recognized to belong to href, the rest doesn't. Quote the values:
echo '', htmlspecialchars($compname), '';
Use this code:
echo ''.$compname.'';
You need add quotes for your href, besides, you also need to use urlencode to encode the variable.
echo '' . $compname . '';
change echo "$compname";
to echo "$compname";
When using double quoted strings " you don't need to paste variables in between, you can just type them.
Also, when pasting strings together don't use comma's , but use . to paste strings otherwise you'll get parse errors.
For arrays include them between curly brackets {}
echo "$compname";

echo plus sign php

I'm echoing a php string variable into html
<span class="title_resource">
<?php echo $titulo; ?>
</span>
But when the plus sign (+) is present, it turns into a space.
I've already tried using urlencode but then I get something like "Constru%25C3%25A7%25C3%"
Should I use something like string replace?
Thanks in advance
Update:
$titulo is setted using $_GET
if (isset($_GET['T']))// title
$titulo = $_GET['T'];
(...)
More clear, perhaps
I want to send exactly this text "Estudo de ax^2 + bx + c". The page receives by $_GET. When I print this value I get "Estudo de ax^2 bx c"
Its the way values as encoded to be sent over using GET, spaces are converted to + and + are converted to %2B.
If you really want to send the plus symbol over the form, then replace the spaces with plus
$text= str_replace(" ", "+", $text);
Next make sure your form uses correct enctype either application/x-www-form-urlencoded or multipart/form-data
I think you should be using urldecode not urlencode ...
<span class="title_resource">
<?php echo urldecode($titulo); ?>
</span>
If this does not work ... can you add the full script .. where you passing , are you using POST etc .. so that i can help you better
:)
Seems like your variable is going through urldecode

Categories