Provided a url, within a string of text (tweet) such as
"Check out my twitpic http://twitpic.com/1876544594 its awesome"
I need a Rails regex that will return 18744594, the id of this particular twitpic...
This question has been asked here but was for PHP, and I need it for Rails.
I would also be able to pull the name of the site, so the text between http:// and .com "twitpic"
To extract 18744594 only
/http:\/\/twitpic\.com\/(\d+)/
To extract twitpic and 18744594
/http:\/\/(twitpic)\.com\/(\d+)/
Related
I'm trying to set up a Twitter share url but it seems to reformat what I'm adding to the url when posting.
What I want:
Hey! Check out the latest #JamesBond DVD at www.example.com
Code:
Tweet-The format I want
<br /><br />
Tweet-Kind Of Half Works - Puts the URL in the wrong place..
What I'm getting:
Hey! Check out the latest
Hey! Check out the latest http://www.example.com/ #JamesBond DVD at
I've fiddled what I have here: https://jsfiddle.net/qnaqmhhL/1/
The format I want is - Text >> Hashtag >> Text >> URL
Any help would be great!
You need to URI Encode the special characters. So, for example # becomes %23.
https://twitter.com/intent/tweet?text=Hey!%20Check%20out%20the%20latest%20%23JamesBond%20DVD%20at%20www.example.com
Clicking on that link will populate the Tweet in the format you want.
I created a hyperlink to a file. the file name contains hashtags as a means to separate information.
<div style="height:100%;width:100%">.</div>
translated to...
http://localhost/dir/upload/1427853638#0#file#A101.pdf
Is this a "legal" name in a URL? Im getting a "file not found" error
The requested URL /dir/upload/1427853638 was not found on this server.
So, clearly the # has another meaning in the URL (I understand now, its a location hash property). Is there a way to get this to work, or do i need to use another character besides the # in the file names?
Since # is a special character in the URL semantic (it's used to provide an internal anchor in a HTML page), it should be URL-encoded into %23.
Your URL should be: http://localhost/dir/upload/1427853638%230%23file%23A101.pdf.
NB: you can find an online URL encoder here: http://meyerweb.com/eric/tools/dencoder/
IM/Email type scenario:
User types whatever they want and sends it to their buddy. If they enter a URL, I want to make it clickable for the recipient. This means we need to identify a sequence of characters within the string is a valid URI and make a hyperlink out of it.
Is there a library to help parse the user input and detect if the user types an internationalized domain name as part of a string?
example:
hey dude this Russian McDonald's site макдональдс.рф is cool - check it out!
Note I am not talking about parsing the URI or doing punycode/Unicode conversions - I need to be able to identify this as a URI first before doing any of that...
if i hit this url "http://stackoverflow.com/questions/9564547" then SO takes me to another url "http://stackoverflow.com/questions/9564547/android-alertdialog-multi-choice-items-with-customised-items". My question is how to implements such a feature and how SO implements it?
What i think of is checking the url parameter id and fetching the title from database and redirecting to the URL. Any better option ?
You need these steps:
Get the question ID from the URL, ignoring any title
Get the question from the database, using that ID
Compare the retrieved title with the supplied title, if any. Allow for SEO changes (space to dash and so on)
If no match, redirect to the correct URL; else continue.
I have a news section where the pages resolve to urls like
newsArticle.php?id=210
What I would like to do is use the title from the database to create seo friendly titles like
newsArticle/joe-goes-to-town
Any ideas how I can achieve this?
Thanks,
R.
I suggest you actually include the ID in the URL, before the title part, and ignore the title itself when routing. So your URL might become
/news/210/joe-goes-to-town
That's exactly what Stack Overflow does, and it works well. It means that the title can change without links breaking.
Obviously the exact details will depend on what platform you're using - you haven't specified - but the basic steps will be:
When generating a link, take the article title and convert it into something URL-friendly; you probably want to remove all punctuation, and you should consider accented characters etc. Bear in mind that the title won't need to be unique, because you've got the ID as well
When handling a request to anything starting with /news, take the next part of the path, parse it as an integer and load the appropriate article.
Assuming you are using PHP and can alter your source code (this is quite mandatory to get the article's title), I'd do the following:
First, you'll need to have a function (or maybe a method in an object-oriented architecture) to generate the URLs for you in your code. You'd supply the function with the article object or the article ID and it returns the friendly URL with the ID and the friendly title.
Basically function url(Article $article) => URL.
You will also need some URL rewriting rules to remove the PHP script from the URL. For Apache, refer to the mod_rewrite documentation for details (RewriteEngine, RewriteRule, RewriteCond).