Replace all characters that aren’t letters and numbers with a hyphen [duplicate]

This should do what you’re looking for: function clean($string) { $string = str_replace(‘ ‘, ‘-‘, $string); // Replaces all spaces with hyphens. return preg_replace(‘/[^A-Za-z0-9\-]/’, ”, $string); // Removes special chars. } Usage: echo clean(‘a|”bc!@£de^&$f g’); Will output: abcdef-g Edit: Hey, just a quick question, how can I prevent multiple hyphens from being next to each … Read more

How to display an image using URL?

The error is most likely that imageURL is nil. Are you assigning it a value elsewhere in the code, or is it actually @IBOutlet in the real code? If you do not assign a value to it, it will be nil – but its type of UIImageView! means it is an “implicitly unwrapped optional” which … Read more

How do I open a URL from C++?

Your question may mean two different things: 1.) Open a web page with a browser. #include <windows.h> #include <shellapi.h> … ShellExecute(0, 0, L”http://www.google.com”, 0, 0 , SW_SHOW ); This should work, it opens the file with the associated program. Should open the browser, which is usually the default web browser. 2.) Get the code of … Read more

What is the definition of an absolute URL (fully qualified?)

RFC 3986 defines Uniform Resource Identifiers. A relative reference that begins with a single slash character is termed an absolute-path reference. A relative reference that does not begin with a slash character is termed a relative-path reference. href=”foo/bar.html” is a relative reference, specifically a relative-path reference. href=”/foo/bar.html” is a relative reference with an absolute path … Read more

ASP.net MVC support for URL’s with hyphens

C# version of John’s Post for anyone who would prefer it: C# and VB version on my blog public class HyphenatedRouteHandler : MvcRouteHandler{ protected override IHttpHandler GetHttpHandler(RequestContext requestContext) { requestContext.RouteData.Values[“controller”] = requestContext.RouteData.Values[“controller”].ToString().Replace(“-“, “_”); requestContext.RouteData.Values[“action”] = requestContext.RouteData.Values[“action”].ToString().Replace(“-“, “_”); return base.GetHttpHandler(requestContext); } } …and the new route: routes.Add( new Route(“{controller}/{action}/{id}”, new RouteValueDictionary( new { controller = “Default”, … Read more

OK to skip slash before query string?

As a matter of modern spec, yes, it is permissible to skip the slash, contrary to what the accepted answer here claims. Although the accepted answer correctly quotes RFC 1738 (released over 20 years ago!), it wrongly claims that RFC 2396 (released in 1998) requires the slash, and neglects that both of those specs have … Read more