Extracting domain name from strings [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
This is my code:
From: =?Shift_JIS?B?Y2VudGVyQHlhbWJnbGUuaW4ubmV0?= < center#yambgle.in.net >
From: =?x-sjis?B?+O6C6IKogvH47iAg?= < autovbxds#netltf.ladankhda.in.net >
I have the php code for the same, but I would like to have a preg_match code for the same.
Please help.

The following regex should do it
$data = 'From: =?x-sjis?B?+O6C6IKogvH47iAg?= < center#yambgle.in.net >';
if(preg_match('/#([^ ]*) /',$data,$result)){
$domain = $result[1];
echo $domain;
}
Result: yambgle.in.net

Related

How to make an php file have an url for example: "example.com/testing/page.php?p=1 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 days ago.
Improve this question
I tried things like
$query = parse_url($url, PHP_URL_QUERY);
// Returns a string if the URL has parameters or NULL if not
if ($query) {
$url .= '&category=1';
} else {
$url .= '?category=1';
echo "hi";
}
?>
but still i cant seem to find the answer.

Replace string with some condition in PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this string
RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=MO,SU
Now the part BYDAY=MO,SU can be in any position like
RRULE:FREQ=WEEKLY;BYDAY=WE,TH;INTERVAL=2;COUNT=5; -> BYDAY=WE
I just want to replace the value of BYDAY=value
let's say I have updated value of BYDAY=FR
I've tried to use str_replace() but the given value of of BYDAY can be anything like MO,TU,WE,TH
Using preg_replace, we can try:
$input = "RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=MO,SU";
$output = preg_replace("/\bBYDAY=[^;]+/", "BYDAY=FR", $input);
echo $input . "\n" . $output;
This prints:
RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=MO,SU
RRULE:FREQ=WEEKLY;COUNT=13;BYDAY=FR

How to format a string returned by a PHP function [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I wrote a program that uses an ISBN to query Amazon for that ISBN's price, and returns the following result:
5cb66919-8a8d-4c13-9175-790f0476508d0.0401580000000000TrueISBN9780340979266OffersAllAll0340979267809USD$8.09688USD$6.88598USD$5.98241010000
I need to format this so that I have the price information in a format that would be understandable to a human.
How can I do this?
Use this way..
<?php
$s = '5cb66919-8a8d-4c13-9175-790f0476508d0.0401580000000000TrueISBN9780340979266OffersAllAll0340979267809USD$8.09688USD$6.88598USD$5.982410100000';
$p = explode('USD',$s);
echo "<pre>";
print_r($p);
echo "</pre>";
?>
function returnPrice($response){
$prices = explode('USD',$response);
unset($prices[0]);
return $prices;
}

regex with php pattern [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
<h3 class="r">curl - Google search results with php - Stack Overflow</h3>
data-href value regex pattern please.
Can try using this pattern
$str = '<h3 class="r">curl - Google search results with php - Stack Overflow</h3>';
$re = '/data-href=["\']?([^"\' ]*)["\' ]/is';
preg_match($re, $str, $m);
$attr_value = trim(str_replace('data-href=', '', $m[0]), '"');
echo $attr_value;
Output:
http://stackoverflow.com/questions/18682352/google-search-results-with-php

Super easy php link construct [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
$out_terms[$term->name] = '' . $text . '';
Please help me check where the code gone wrong,any missing notes etc,as I am really 0 into php
$out_terms[$term->name] = sprintf('%s', $term_link, $text);
Try this (best construct) :
$out_terms[$term->name] = "$text";
or :
$out_terms[$term->name] = ''.$text.'';

Categories