Question about the url intercepted by php from a string

Source: Internet
Author: User
Hello, the question of intercepting URLs from strings in php is: first, I won't use php, but I hope you can solve this problem for me, thank you very much for calling a string $ longurl from a php program. The result of $ longurlecho is www.csdn.net/123456<ahref=http://www. question about intercepting URLs from strings in php
Hello everyone. First of all, I don't know php, but I hope you can solve this problem for me. thank you very much.

I call a string $ longurl from a php program

The result of the $ longurl echo is
Www.csdn.net/123456click here

How can I intercept the section www.csdn.net/123456?

What I found online is

$ Aa = $ longurl;
Preg_match ("/http [^ \"] */", $ aa, $ bb );
Echo $ bb [0];

However, in the next program, I want to shorten the Baidu short URL api

Program is

$ Urlbd = '$ bb [0]';
$ Result = getBaiduShortUrl ($ urlbd );
If ($ result ){
Echo 'success: '. $ result;
} Else {
Die ('failed ');
}

Function getBaiduShortUrl ($ urlbd ){
$ Data = array (
'URL' => $ urlbd,
);
$ Baidu_url = 'http: // dwz.cn/create.php ';
$ Ret = postData ($ baidu_url, $ data );
If ($ ret ){
$ Ret = json_decode ($ ret, true );
If ($ ret ['status']! = 0 ){
Return false;
} Else {
Return $ ret ['tinyurl'];
}
} Else {
Return false;
}
}


Function postData ($ urlbd, $ data ){
$ Options = array (
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => 'gzip, deflate, sdch ',
CURLOPT_USERAGENT => 'mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/11.10 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/80 ',
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT = & gt; 120,
CURLOPT_TIMEOUT => 120,
CURLOPT_MAXREDIRS => 10,
CURLOPT_REFERER => 'http: // www.baidu.com /',
CURLOPT_POSTFIELDS => $ data,
);

$ Ch = curl_init ($ urlbd );
Curl_setopt_array ($ ch, $ options );
$ Content = curl_exec ($ ch );
$ Err = curl_errno ($ ch );
$ Errmsg = curl_error ($ ch );
$ Header = curl_getinfo ($ ch );
Curl_close ($ ch );

Return $ content;
}


What's wrong with the shortened address? could you please help me check it out?


------ Solution --------------------
You cannot get the regular expression you want, and $ urlbd = '$ bb [0]'. you define $ urlbd as a string of $ bb [0 ].
You must use double quotation marks to replace the variables in the parsing with the following
Preg_match ("/] *>. * <\/a>/I", $ aa, $ bb );
$ Urlbd = $ bb [1];
------ Solution --------------------
Just now csdn has crashed again.

How can I intercept the section www.csdn.net/123456?

Click here from www.csdn.net/123456.
Extract www.csdn.net/123456?

If so, there are many methods to shorten the website. I don't know if there are any other Web sites. do this for the time being?
$ Str = 'www .csdn.net/123456 ';
Preg_match ('/^ ([a-z \ d \. \/] +) $ urlStr = $ match [1];
Echo $ urlStr;
Result
Www.csdn.net/123456

------ Solution --------------------
Www.csdn.net/123456click here
To intercept all the characters $ s1, use $ strArray = explode ("------ solution --------------------
I mean:
I call a string $ longurl from a php program

The result of the $ longurl echo is
Www.csdn.net/123456click here
Are the $ longurl strings in this rule {url address! If yes, you can use the php string separation function to separate it, and then return an array:
$ StrArray = explode ("print_r ($ strArray );

What is the result?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.