#NEEDED SMART FELLA NOT FART SMELLA

3 messages · Page 1 of 1 (latest)

sullen jay
#

I CREATED THIS FUNC TO MAKE EVERY HOTEL NAME gets created new line so like this
02.14 - 02.17 ( 3 N ) THE APURVA KEMPINSKI BALI
02.14 - 02.17 ( 3 N ) THE APURVA KEMPINSKI BALI
instead of this 02.14 - 02.17 ( 3 N ) THE APURVA KEMPINSKI BALI 02.14 - 02.17 ( 3 N ) THE APURVA KEMPINSKI BALI

#

function formatHotelTextUltraSimple($text)
{
if (empty($text) || $text === 'NOT FOUND') {
return $text;
}

// Clean the text first
$text = preg_replace('/\s+/', ' ', $text);
$text = trim($text);
// Pattern to match hotel entries: date range + ( X N ) + hotel name
// Example: 02.14 - 02.17 ( 3 N ) THE APURVA KEMPINSKI BALI
$pattern = '/(\d{2}\.\d{2}\s*-\s*\d{2}\.\d{2})\s*\(\s*(\d+)\s*N\s*\)\s*([^0-9]+)/';

// Find all hotel entries
preg_match_all($pattern, $text, $matches, PREG_SET_ORDER);

if (count($matches) > 0) {
    $formattedHotels = [];
    foreach ($matches as $index => $match) {
        $dateRange = trim($match[1]);
        $nights = trim($match[2]);
        $hotelName = trim($match[3]);

        $formattedEntry = "$dateRange ( $nights N ) $hotelName";
#

if ($index > 0) {
// Indent subsequent hotel entries
$formattedEntry = "\t\t\t\t" . $formattedEntry;
}

        $formattedHotels[] = $formattedEntry;
    }

    return implode("\n", $formattedHotels);
}

// If pattern not found, fall back to original logic
// Replace "BALI " with "BALI\n\t\t\t\t"
$originalText = $text;
$text = str_replace('BALI ', "BALI\n\t\t\t\t", $text);

if ($text === $originalText) {
    $text = str_replace('BALI  ', "BALI\n\t\t\t\t", $text);
}

if ($text === $originalText) {
    $text = str_replace('BALI   ', "BALI\n\t\t\t\t", $text);
}

if ($text === $originalText) {
    $baliPos = strpos($text, 'BALI');
    if ($baliPos !== false) {
        $afterBaliPos = $baliPos + 4;
        $text = substr($text, 0, $afterBaliPos) . "\n\t\t\t\t" . substr($text, $afterBaliPos);
    }
}

return $text;

}