News:

Want to get involved in developing SMF? Why not lend a hand on our GitHub!

Main Menu

Need advice about Ampersands in forums searches?

Started by I Agree, January 23, 2009, 07:13:18 PM

Previous topic - Next topic

I Agree

We have links in our blog that point to a post in the forum named after the headline in the blog post. The link is generated by using a SMF search url with the query embedded in the url. Today we ran into a prob though, as one of the blog titles has an & in the title (part of the name of the company involved)

The problem is if you do a quoted search which includes an ampersand the search engine cuts the query off at the ampersand. I'm fairly certain it is actually getting cut by PHP's handing of the "get" arguments in the url, but replacing the ampersand with %26 doesn't seem to help.

However even if I manually give the quoted search string to the smf search page, it doesn't find the thread with the same title, though it accepts the entire search.

NEMINI

signatures are boring.

I Agree

#2
Quote from: NEMINI on January 23, 2009, 07:57:28 PM
try replacing with & instead of %26

Hmmm, I'd thought I already tried this, but I went ahead and tried again and it worked. I guess I had tried it one way or another, but not directly on the search page. It's kinda weird to have to put that into a search engine but it works (for now)

However, we're still stuck, as much as I'm thankful for the input... still needed is a way to embed this in the url and sneak it past PHP. Best I can tell PHP is treating the & (which is still needed with &) as a separate argument even when embedded in quotes. Using %26 appears to achieve absolutely nothing, as PHP still seems to treat it as an argument delimiter :-\

NEMINI

sounds like the blog isn't properly converting the initial ampersand to the proper & when its sent to the database.

Have you tried editing the title of the blog to use & instead of an ampersand?  I'm curious to see if once written as & whether the software will display it properly.
signatures are boring.

I Agree

Well, I've tried all this stuff manually from the browser address bar. It's possible the address bar might do some pesky conversions, but I was putting off re-coding the blog until I figured out what would work.

NEMINI

the blog code should take & and convert it to & and then translate it back when displayed. (also true for other symbols too, they all have html versions).
signatures are boring.

I Agree

I went ahead and tried that, but basically browsers convert all of that in the final rendered page (including where the link points to) so it doesn't seem really possible to fit & into the url from what I know... including passing it thru the browser and the php handling of the subsequent link :(

I Agree

Another hurdle is the SMF syntax seems to use semicolons for delimiting stuff in the action argument :o

I Agree

I'm wondering if it might overcome a lot of these hurdles if I make the link a form submit, so I can pass everything to the search page via post. That should have to work I suppose, otherwise the search page wouldn't work :-\

I Agree

#9
Ok, we use this now...

<form id="discussion-submit" target="_blank" action="/bbs/index.php?border=WP&action=search2;brd[]=15;subject_only=1;" method="post" accept-charset="UTF-8" style="display:none">

<textarea name="search">"NEWS: <?php echo str_replace(array("&amp;nbsp;","&"),array(" ","&amp;"),htmlspecialchars(strip_tags($post->post_title))); ?>"</textarea>
</form>

<a href="javascript:document.getElementById('discussion-submit').submit()">Forum Discussion »</a>


Get's the job done as long as no entities other than &nbsp; are used in titles. Thanks for your patience O:)

I Agree

Hello again,

This was working fine at the time. But since this website was moved to a new server. I'm think this current server must have some restrictions or lacks some basic capabilities that are causing some trouble.

It has nothing to do with this process here as far as I can tell. The problem is basically any longish search string causes the results to pretty much never come back. And when linking to a search page via post eventually the page just comes up blank (or however the browser likes to handle this situation)

So no matter how the search is handed off to SMF (even via the forums search page) if you ask it to search for say the exact/longish subject of a particular thread it just goes into an infinite waiting for response mode.

We are planning on moving to a better situation but in the meantime I'd like to make this work for our users if possible.

Any ideas?

Advertisement: