Welcome Guest, Not a member yet? Register   Sign In
spaces in URL links
#1

[eluser]nir[/eluser]
Hello all,

i am trying to generate anchor url links based on entries from a field in a database as follow:
Code:
'<a href='.base_url().'>'.$row['city'].'</a>'

when the entry in the database has no space the anchor link would work just fine, but when there is a space (e.g. Los Angeles) the link would be something like ..../index.php?/city/edit/Los , which will results in no data when clicking on the link.
i am aware of the html encoding but i do not no how to actually do it for the generated anchor url links.

thx in advanced,
nir
#2

[eluser]Krystian[/eluser]
I don`t exactly know what do you mean but ... if links

Code:
echo '<a href=' . base_url() . $row['>' . $row['city'] . '</a>';
#3

[eluser]Colin Williams[/eluser]
Your HTML is malformed. You should encapsulate the href attribute in double-quotes.
#4

[eluser]nir[/eluser]
that is what i was trying
Code:
'<a href='.base_url()./edit/'>'.$row['city'].'</a>'
#5

[eluser]Colin Williams[/eluser]
There are still no quotes there. Try:

Code:
'<a href="'.base_url()./edit/'">'.$row['city'].'</a>'
#6

[eluser]BrianDHall[/eluser]
You can also do (test to see if the board's security parser is a little more forgiving, I think it is eating some earlier submissions:

EDIT - yeah, it's eating it. Trying again:

Code:
echo '<a href="' . urlencode($row['city']) . '">' . urldecode($row['city'] . '</a>';

To handle spaces, http://php.net/manual/en/function.urlencode.php

Code untested, but the general theory is correct Wink
#7

[eluser]nir[/eluser]
thank you.
the url link looks fine now, it has the whole word (e.g .../edit/Los Angles) but the parameter that is being passed to the model gets an underscore, so, it looks as Los_Angeles and the query returns NULL since there are no entries for Los_Angeles.

thx,
nir
#8

[eluser]Colin Williams[/eluser]
That's one of the drawbacks of using PATH_INFO. Try setting uri_protocol to REQUEST_URI
#9

[eluser]nir[/eluser]
Hi Colin,

thank you for your help. I tried changing the uri_protocol, but, now thw sql query looks as follow:
SELECT items FROM table WHERE city = 'Los Angeles' ORDER BY city.
which returns NULL.

thanks again,
nir
#10

[eluser]John_Betong[/eluser]
&nbsp;
I would be tempted to:
1. use $this->load->helper('url');
2. save all the cities into your database table using url_title()
3. search for user input using '<a href='.base_url().'>'. url_title($row['city']).'</a>'
4. display the results using str_replace('_', ' ', $row->city);
&nbsp;
&nbsp;
&nbsp;




Theme © iAndrew 2016 - Forum software by © MyBB