How to parse HTML and preformat using php [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have text like this Too early to post? http://www.somewebsite.com/article/226973 I want to parse the hyperlinks in the text and make the text look like so Too early to post? http://www.entrepreneur.com/article/226973 I want to do this but I have no idea where to start from or what regexp to use.

$s = 'Too early to post? https://www.somewebsite.com/article/226973';
$parsed = preg_replace('#(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)#', '$1', $s);
echo $parsed;

Related

Select text on a string after X symbol [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 8 years ago.
Improve this question
i have this string
$string = "Social\Notify\Models\User";
How can i tell to php how select just the fourth segment of it? in this case just the word User?
Something like this will do?
$str='Social\Notify\Models\User';
echo explode('\\',$str)[3]; //"prints" User

JavaScript regex and replace like PHP preg_replace [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have following code in php:
$link ='mylink';
$description = '<p><img src="http://l3.yimg.com/bt/api/res/1.2/hmYETKsJS2CXBsG7oO125w--/YXBwaWQ9eW5ld3M7Zmk9ZmlsbDtoPTg2O3E9ODU7dz0xMzA-/http://media.zenfs.com/en_us/News/Reuters/2013-09-07T045234Z_3_CBRE9851BPL00_RTROPTP_2_RUSSIA-G20.JPG">By Roberta Rampton and Susan Cornwell WASHINGTON (Reuters) - ...</p>';
$pattern = "/(?<=href=(\"|'))[^\"']+(?=(\"|'))/";
$new_des = preg_replace($pattern,"?url=".$link,$description);
How can I do that in javascript?
pattern = /(href=["'])[^"']+(?=["'])/
new_des = description.replace(pattern, "$1?url=" + link)
JS doesn't support lookbehinds, therefore you'll have to capture the first group and insert it back when replacing using $1.

php filter with get variables [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I suck at regexp but i'd like to just do a simple filter where / is replaced with 1, " is replaced with 2 and < is replaced with 3.
I'd appreciate an example where the syntax would be straight forward, i'd like to run this filter through the input of a get variable provided by the user. A syntax like:
replace(/,1)
replace(",2)
replace(<,3)
.
Thanks.
I really don't see the need for regex here.. You can just use str_replace
E.g.
str_replace('/', '1', $_GET['var']);

Matching string with preg_match [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following string formats: "$ 3.20" or "$ 10.34". I want to verify with preg_match if the string is exactly this type of a format.
Any suggestions are appreciated?
Try this pattern:
if (preg_match('/\$\s[\d]+\.[\d]{2}/', $text)){
//do something
}

PHP Text area foreach line [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Im trying to code a php script that will loop a process for each line in a Textarea post. I was wondering if someone can post an example.
foreach(explode("\n", $text) as $line) {
// do something
}
See the manual page on explode()
You might have to use \r\n instead of just \n for textarea (I remember figuring it out for quite a while)

Categories